转:http://blog.csdn.net/woshicaixianfeng/article/details/7261718
在项目中,一进入一个页面, EditText默认就会自动获取焦点。
那么如何取消这个默认行为呢?
在网上找了好久,有点 监听软键盘事件,有点 调用 clearFouse()方法,但是测试了都没有! xml中也找不到相应的属性可以关闭这个默认行为
解决之道:在EditText的父级控件中找一个,设置成
android:focusable="true"
android:focusableInTouchMode="true"
这样,就把EditText默认的行为截断了!
<RelativeLayout android:id="@+id/RL_main_bottom_bar" android:layout_width="match_parent" android:layout_height="@dimen/bottom_bar_height" android:layout_alignParentBottom="true" android:background="@android:color/white" android:focusable="true" android:focusableInTouchMode="true"> <ImageView android:id="@+id/IV_main_setting" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="10dp" android:src="@drawable/ic_settings_black_24dp" /> <EditText android:id="@+id/EDT_main_topic_search" android:layout_width="match_parent" android:layout_height="26dp" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_toLeftOf="@id/IV_main_setting" android:background="@drawable/edittext_rounded_corner_bg" android:drawableLeft="@drawable/ic_search_white_18dp" android:drawableTint="@color/button_disable_color" android:textColor="@android:color/white" /> </RelativeLayout>