我有带有按钮和编辑文本的弹出窗口。然后我触摸编辑文本或使用
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);keyboard
应用崩溃了。
错误是: java.lang.IllegalArgumentException: 添加窗口后窗口类型不能改变。
代码:
LayoutInflater layoutInflater = (LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup_over_map, null);
Context context = this.getActivity().getApplicationContext();
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(metrics);
int displayWidth = metrics.widthPixels;
int displayHeight = metrics.heightPixels;
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(displayWidth - 10, displayHeight - 125);
layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
final PopupWindow popupWindow = new PopupWindow(popupView,
layoutParams.width, layoutParams.height, true);
popupWindow.setSoftInputMode(WindowManager.LayoutParams.
SOFT_INPUT_STATE_VISIBLE);
Button btnDismiss = (Button) popupView.findViewById(R.id.close_window_btn);
btnDismiss.setOnClickListener(this);
etTimeUntil = (EditText)popupView.findViewById(R.id.time_et);
checkOnDemand = (CheckBox) popupView.findViewById(R.id.check_ondemand_popup);
....
最佳答案
请检查您的 list ,目标版本应小于 14 或删除目标版本标签....!
<uses-sdk
android:targetSdkVersion="11"/>
我也遇到过这个问题,这对我有用,祝你好运......!
关于android - 如果显示软键盘弹出窗口崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32938546/