当我将弹出式窗口设置为外部可触摸以错误编辑文本时,在弹出窗口中不显示键盘

问题描述 投票:0回答:2

我的活动上有一个PopupWindow,popupWindow具有“编辑”文本。问题是,当我将外部可触摸的弹出窗口设置为false时,编辑文本无法在android的弹出窗口中打开键盘,并且我通过在弹出窗口内设置取消按钮来关闭弹出窗口。请事先感谢您的帮助。

 LayoutInflater inflater = (LayoutInflater)
                    getSystemService(LAYOUT_INFLATER_SERVICE);
            final View popupView = inflater.inflate(R.layout.repeat, null);
            int width = LinearLayout.LayoutParams.MATCH_PARENT;
            int height = LinearLayout.LayoutParams.WRAP_CONTENT;
            boolean focusable = false; 
            final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable);

            // show the popup window
            // which view you pass in doesn't matter, it is only used for the window tolken
            popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
            final LinearLayout until = popupView.findViewById(R.id.Until);
            Button pop_done = popupView.findViewById(R.id.pop_done);
            Button pop_cancel = popupView.findViewById(R.id.pop_cancel);
            dropdown = popupView.findViewById(R.id.spinner);
            final EditText repetition = popupView.findViewById(R.id.repeat_times);
android android-popupwindow
2个回答
0
投票

[repetition.requestFocus();应该显示键盘。


0
投票
  • 尝试一下

    LayoutInflater inflater = (LayoutInflater)
                    getSystemService(LAYOUT_INFLATER_SERVICE);
            final View popupView = inflater.inflate(R.layout.repeat, null);
            int width = LinearLayout.LayoutParams.MATCH_PARENT;
            int height = LinearLayout.LayoutParams.WRAP_CONTENT;
            final PopupWindow popupWindow = new PopupWindow(popupView, width, height);
            popupWindow.setFocusable(true);
            popupWindow.update();
            // show the popup window
            // which view you pass in doesn't matter, it is only used for the window tolken
            popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0);
            popupWindow.setOutsideTouchable(false);
            final LinearLayout until = popupView.findViewById(R.id.Until);
            Button pop_done = popupView.findViewById(R.id.pop_done);
            Button pop_cancel = popupView.findViewById(R.id.pop_cancel);
            Spinner dropdown = popupView.findViewById(R.id.spinner);
            final EditText repetition = popupView.findViewById(R.id.repeat_times);
    
© www.soinside.com 2019 - 2024. All rights reserved.