Show soft keyboard when Activity starts

前端 未结 10 581
梦毁少年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:52

    I have got two way.

    Method 1. Use the following code inside the OnCreate method

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    

    It will prevent popping up keyboard unless you click.

    or

    Method 2 You can move away the focus on other view like TextView by using "requestfocus" in the xml.

                
               
               
    

    Method 3 ( I think it should be avoidable) Using the following code in the manifest-

    android:windowSoftInputMode="stateVisible"
    

提交回复
热议问题