Android show softkeyboard with showSoftInput is not working?

后端 未结 12 2165
抹茶落季
抹茶落季 2020-12-28 13:49

I have created a trivial application to test the following functionality. When my activity launches, it needs to be launched with the softkeyboard open.

My code doe

12条回答
  •  青春惊慌失措
    2020-12-28 14:23

    This answer maybe late but it works perfectly for me. Maybe it helps someone :)

    public void showSoftKeyboard(View view) {
        if (view.requestFocus()) {
            InputMethodManager imm = (InputMethodManager)
                    getSystemService(Context.INPUT_METHOD_SERVICE);
            boolean isShowing = imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
            if (!isShowing)
                getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
        }
    }
    

    Depends on you need, you can use other flags

    InputMethodManager.SHOW_FORCED
    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    

提交回复
热议问题