문제

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.

도움이 되었습니까?

해결책

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);
        }
    }

다른 팁

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top