EditText doesn't start automatically

2019-06-02 07:46发布

问题:

In my app, I have an EditText. How do I make it doesn't start automatically? Like: once they open the activity it automatically sets the mouse to the EditText and the keyboard gets opened so they type…

Is there anyway I can make it open (the keyboard shows and the user can type) when they clicks on it?

回答1:

Ok, so from your question i figure out that your EditText is getting focus while starting the activity. You can disable the focus using following command to suppress the keyboard.

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

Visit this Close/hide the Android Soft Keyboard



回答2:

the answer by Lucifer must work. But when i got the same problem, that solution did't work, and someone suggested me this.

add a fake layout as the first element in you parent layout and make it focusable.

Like this:

<ParentLayout
     .....
     ......>
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@android:color/transparent"
        android:focusable="true"
        android:focusableInTouchMode="true" >
    </LinearLayout>

     ......
     ......
     ......

</ParentLayout>

This definitely works, but the best solution is:

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