原文鏈接: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>??