我在scrollView中有一個按鈕。當按鈕被點擊時,只要點擊按鈕,我需要一個PopupWindow來顯示軟鍵盤。這是我的代碼看起來今天:Android:PopupWindow填充鍵盤上方的空間
final Button b = (Button) findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView,WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT,true);
popupWindow.showAtLocation(v.getRootView(), Gravity.FILL, 0, 0);
//Bring soft keyboard up : NOT WORKING
final InputMethodManager mInputMethodManager = (InputMethodManager) getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE);
EditText editText = (EditText) popupView.findViewById(R.id.editText);
mInputMethodManager.showSoftInput(editText, 0);
}
});
和我的佈局XML是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/yourViewsEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Your Views"
>
</EditText>
</RelativeLayout>
當我嘗試FILL_PARENT代替WRAP_CONTENT,它通過填充整個屏幕開始了。我想實現這樣的事情:
它現在看起來怎麼樣? – waqaslam