【问题标题】:popup window crash if show soft keyboard如果显示软键盘,弹出窗口崩溃
【发布时间】:2016-01-01 12:23:12
【问题描述】:

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

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);
            ....

【问题讨论】:

    标签: android keyboard popupwindow


    【解决方案1】:

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

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

    我也遇到过这个问题,这对我有用祝你好运......!

    【讨论】:

    • 检查您的 PopUpView 配置...!
    猜你喜欢
    • 1970-01-01
    • 2018-03-08
    • 1970-01-01
    • 2015-07-24
    • 2023-03-25
    • 2014-08-24
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多