原文链接:http://blog.csdn.net/tablle/article/details/51659277
---------------------
1、禁止进入activity后EditText自动获得焦点的方法
在项目中,一进入一个页面, EditText默认就会自动获取焦点。
那么如何取消这个默认行为呢?
在网上找了好久,有监听软键盘事件,有调用 clearFouse()方法,但是测试了都没用。xml中也找不到相应的属性可以关闭这个默认行为 。
解决之道:在EditText的父级控件中找一个,设置成
android:focusable="true"
android:focusableInTouchMode="true"
这样,就把EditText默认的行为截断了!
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:focusable="true"
- android:focusableInTouchMode="true" >
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="@color/title_name"
- android:textSize="16sp" />
-
- <EditText
- android:layout_width="match_parent"
- android:layout_height="125dp"
- android:background="@drawable/edit_edittext_bg"
- android:gravity="top"
- android:hint="说一说!"
- android:padding="6dp"
- android:textColor="@color/project_bulid_item_textcolor"
- android:textSize="12sp" />
- </LinearLayout>
- </RelativeLayout>