Show soft keyboard when Activity starts

前端 未结 10 562
梦毁少年i
梦毁少年i 2020-12-13 08:28

I have 2 activities, A and B. When A starts, it checks for a condition and if true, it calls startActivityForResult() to start B. B only takes text input so it

相关标签:
10条回答
  • 2020-12-13 08:33

    If requestFocus on an EditText isn't showing it, maybe this'll do it:

    InputMethodManager imm = (InputMethodManager)getSystemService(
        Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(mEditText, 0);
    

    Look here for more information.

    0 讨论(0)
  • 2020-12-13 08:35

    Major Attention Required!

    android:windowSoftInputMode="stateVisible|adjustPan" This alone won't work to show keyboard on activity start.

    You also need to explicitly add this into your class

    editTextXYZ.requestFocus()
            val imm: InputMethodManager =
                getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.showSoftInput(editTextXYZ, InputMethodManager.SHOW_IMPLICIT)
    
    0 讨论(0)
  • 2020-12-13 08:37

    File : AndroidManifest.xml

    <activity android:name=".MainActivity">
    

    Add following property :

    android:windowSoftInputMode="stateVisible"
    

    Which worked for me.

    0 讨论(0)
  • 2020-12-13 08:42

    If you're using an emulator, you have to turn the hard keyboard off in order for the soft keyboard to show.

    0 讨论(0)
  • 2020-12-13 08:52

    What worked best for me is in Android Manifest for activity B adding

    android:windowSoftInputMode="stateVisible"

    Hope that helps for you as well.

    0 讨论(0)
  • 2020-12-13 08:52

    Easiest solution: Put

    android:windowSoftInputMode = "stateVisible" 
    

    in Activity section of AndroidManifest.xml

    0 讨论(0)
提交回复
热议问题