简体   繁体   中英

Android softkeyboard not triggerring

I have multiple EditText on my screen and one of them is focussed. The softkeyboard does not trigger as soon as the screen pops up. I want the soft keyboard to trigger as soon as the screen pops up. It works well if I don't implement the onFocusChangeListener() . However I need the onFocusChangeListener() to detect which editText is focused. I have tried setting setFocusable(true) and setFocusableInTouchMode(true). Also i don't want to modify the android:windowSoftInputMode property in AndroidMenifest.xml. I have the following criteria :

  1. onFocusChangeListener implemented (to detect which edittext is focused)
  2. No modifications in AndroidMenifest.xml

Here is my code snippet

final InputMethodManager inputMethodManager =  (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

    mInput.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            mIsFocused = hasFocus;
            if(hasFocus)
                inputMethodManager.showSoftInput(mInput, InputMethodManager.SHOW_IMPLICIT);

        }
    });

Any suggestions ?

您可以通过编程方式打开软键盘

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

You can try using inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0) .

Source: Stackoverflow post

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