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

标签 android keyboard popupwindow

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

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/

相关文章:

ios - 如何在 iOS 8 中获取第三方键盘大小?

javascript - 如何使用 javascript 制作带有复选框的弹出窗口?

javascript - 在 Javascript 中使用 Window.prompt()

android - Android 中的应用程序如何使用 SurfaceFlinger 实例?

java - 将 GridView 的内容居中

java - Android Spinner 显示文本问题

javascript - 弹出窗口打开事件后不起作用

android - 如何在 Android Fragments 中添加操作栏选项菜单

ios - Flutter iOS 键盘问题 : "." Character Missing in TextInputType. 号码

ios - 键盘约束问题