我在 scrollView 中有一个按钮。单击该按钮时,我需要一个 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 时,它会从填充整个屏幕开始。我正在尝试实现这样的目标: