2

Is there a way to get key events when forcing keyboard this way in Fragment onCreateView method:

    getActivity().getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

Also would need the keyboard to be in numeric mode.

Thanks.

2 Answers 2

1

You can listen keyboard presses if you override onKeyDown method in your activity

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            ...
            return true;
            ...
        default:
            return super.onKeyDown(keyCode, event);
        }
    }
0

There are two methods to show soft keyboard even if you dont have any edit text to focus on,

first-

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInputFromWindow(viewToAnchorTo.getWindowToken(), 0);

Second-

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.