android: get rid of focus when enter activity

Possible Duplicate:
Stop EditText from gaining focus at Activity startup?

I have an activity has a EditText inside, and each time when the activity starts up, the EditText automatically get the focus.

I don't want the EditText gets the focus automatically, how can I do?


I had the similar issue and i am sure this is the problem, for that you just need to do a small trick.

Add this LinearLayout before the EditText which is getting focus at activity startup. You don't need to set any value inside the EditText.

<LinearLayout
    android:focusable="true" 
    android:focusableInTouchMode="true"
    android:layout_width="0dip" 
    android:layout_height="0dip"
    android:id="@+id/dummyView"/>

在您的清单中的<activity>标记中添加此标记,以查看edittext所在的活动。

android:windowSoftInputMode="stateHidden"

android:focusable="false" focusable android:focusable="false"可能会对edittext有效

链接地址: http://www.djcxy.com/p/24162.html

上一篇: 如何防止滚动聚焦EditText

下一篇: android:输入活动时摆脱焦点