简体   繁体   English

点击按钮后显示软件键盘

[英]Show software keyboard after tap button

I need to show the software keyboard after the user clicks on a button. 用户单击按钮后,我需要显示软件键盘。 Now I am hiding the keyboard and showing it after user clicks on button, but when the user clicks on an Edit-text, the keyboard shows itself. 现在,我将隐藏键盘并在用户单击按钮后显示它,但是当用户单击“编辑文本”时,键盘将显示其自身。 I has two button, when user clicks at first button he see softwear keyboard, when he click at second button the softwere keyboard is hiding and he see control fragment, which controls edittext. 我有两个按钮,当用户单击第一个按钮时,他看到软件键盘,当他单击第二个按钮时,软件键盘被隐藏,并且他看到控件片段,该片段控制edittext。 And when user sees the control fragment and tap for edittext the softwear keyboard is displayed. 当用户看到控件片段并点击以获取编辑文本时,将显示软键盘。 I need that to not show this softwear keyboard. 我需要不要显示此软键盘。 Softwear keyboard should be shown only when the user taps on the first button 仅当用户点击第一个按钮时,才显示软键盘

How can I stop the soft keyboard showing, but have it still working when clicked on the button? 我如何才能停止显示软键盘,但是单击该按钮后它仍然可以工作?

set editText.setFocusable(false); 设置editText.setFocusable(false); initiall and on button click use editText.setFocusable(true); 初始化并单击按钮,使用editText.setFocusable(true); and editText.requestFocus(); editText.requestFocus();

这将为您提供帮助。

editText.setInputType(InputType.TYPE_NULL);
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus) {
            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }
    }
});

To force the soft keyboard to appear, you can use 要强制显示软键盘,可以使用

EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

And for removing the focus on EditText, saddly you need to have a dummy View to grab focus. 而要取消对EditText的关注,可悲的是,您需要一个虚拟View来获取焦点。

I hope this helps To close it you can use 我希望这可以帮助您关闭它

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM