Button to display and / or hide keyboard

1

A% num numeric% will receive input via external keyboard, then display the default keyboard, it should be optional.

How do I:

When you click on EditText to position the cursor, the keyboard does not open?

Open / close the keyboard with a separate button?

    
asked by anonymous 12.04.2018 / 18:02

2 answers

4

I used the following form:

Show / Hide in same role ( toggleSoftInput ):

InputMethodManager imm = (InputMethodManager) getSystemService(this.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, 0);

Only hide ( hideSoftInputFromWindow ):

InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

Only display ( showSoftInput ):

InputMethodManager imm = (InputMethodManager) getSystemService(this.INPUT_METHOD_SERVICE);
        imm.showSoftInput(this.cod, InputMethodManager.SHOW_IMPLICIT);
    
17.04.2018 / 15:22
3
etNumerico.setInputType(InputType.TYPE_NULL);

Try the above way to define that it will not call the virtual keyboard. And to show or hide the keyboard by a button like this:

//Mostrar e esconder
 private void funcaoTeclado() {
    View v = getActivity().getCurrentFocus();

    if (v != null) {

        InputMethodManager inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);

        inputManager.toggleSoftInputFromWindow(v.getWindowToken(), InputMethodManager.SHOW_FORCED, InputMethodManager.RESULT_UNCHANGED_SHOWN);
    }
}

I'm using getActivity because I'm using it in a snippet, so that part of the code may change according to the context of your app

    
12.04.2018 / 19:29