如果显示软键盘弹出窗口崩溃

时间:2015-10-04 21:22:16

标签: android keyboard popupwindow

我有弹出按钮和编辑文字。然后我触摸编辑文本或使用

InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);keyboard

app崩溃了。

错误是: 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);
            ....

1 个答案:

答案 0 :(得分:3)

请检查您的清单,目标版本应小于14或删除目标版本标记....!

<uses-sdk
    android:targetSdkVersion="11"/>

我在这个问题上也遇到过这个对我有用的东西祝你好运......!

相关问题