简体   繁体   中英

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. 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); initiall and on button click use editText.setFocusable(true); and 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.

I hope this helps To close it you can use

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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