[英]popup window crash if show soft keyboard
I have popup with buttons and edit text. 我有弹出按钮和编辑文本。 Then I touch edit text or use
然后我触摸编辑文本或使用
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);keyboard
app crashed. 应用程序崩溃了。
Error is: java.lang.IllegalArgumentException: Window type can not be changed after the window is added. 错误是:java.lang.IllegalArgumentException:添加窗口后无法更改窗口类型。
Code: 码:
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);
....
Please check your manifest, the targetted version should be less than 14 or remove targetted version tag....! 请检查您的清单,目标版本应小于14或删除目标版本标签....!
<uses-sdk
android:targetSdkVersion="11"/>
I also encountered in this problem this is what which worked for me Good luck...! 我也遇到过这个问题,这对我有用吗祝你好运......!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.