EditText doesn't start automatically

2019-06-02 07:19发布

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?

2条回答
淡お忘
2楼-- · 2019-06-02 07:28

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);
查看更多
小情绪 Triste *
3楼-- · 2019-06-02 07:51

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

查看更多
登录 后发表回答