【Android笔记】EditText文本框不获取焦点

【Android笔记】EditText文本框不获取焦点

在开发中,常常会碰到这种情况,打开一个activity后,

第一个文本框自动获得焦点,同时会弹出软键盘输入框,这样很影响用户体验。

解决方法:

 1、不让文本框获得焦点,抢占文本框的焦点,如在其父窗体中加入:

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical"
 6     android:focusable="true"
 7     android:focusableInTouchMode="true"
 8     tools:context=".MainActivity" >
 9      
10      <EditText
11         android:id="@+id/etMsg"
12         android:layout_width="wrap_content"
13         android:layout_height="wrap_content"
14         />
15 </LinearLayout>

 2、获得焦点不弹出输入框,在activity中加入:

1 android:windowSoftInputMode = "stateHidden"

参考原文:http://my.oschina.net/helu/blog/142020