Android取消EditText自动获取焦点默认行为
生活随笔
收集整理的這篇文章主要介紹了
Android取消EditText自动获取焦点默认行为
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在項目中,有時候想要編輯框開始不獲取焦點,當點擊編輯框獲得焦點時,會調到下一個Activity中。
一般情況下,一進入一個頁面, EditText默認就會自動獲取焦點。
解決之道:在EditText的父級控件中找一個,添加這兩個屬性:
android:focusable="true" android:focusableInTouchMode="true" 這樣,就把EditText默認的行為截斷了!
?例如:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent" android:focusable="true"android:focusableInTouchMode="true"><!-- 這兩句是為了取消自動獲取焦點 --><com.baidu.mapapi.map.MapViewandroid:id="@+id/id_bmapView"android:layout_width="fill_parent"android:layout_height="fill_parent"android:clickable="true" /><EditTextandroid:id="@+id/search_edittext"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginTop="15dp"android:background="@drawable/search_bar_edit_bg"android:drawableLeft="@drawable/search_bar_icon_normal"android:hint="搜索"android:selectAllOnFocus="true"android:singleLine="true"android:textColor="#000" ></EditText><Buttonandroid:id="@+id/button_selector"android:layout_width="40dp"android:layout_height="40dp"android:layout_alignParentRight="true"android:layout_alignParentTop="true"android:layout_marginRight="25dp"android:layout_marginTop="100dip"android:background="@drawable/mmm" /><Buttonandroid:id="@+id/traffic"android:layout_width="40dp"android:layout_height="40dp"android:layout_alignLeft="@+id/button_selector"android:layout_below="@+id/button_selector"android:layout_marginTop="15dp"android:background="@drawable/traffic" /></RelativeLayout>
總結
以上是生活随笔為你收集整理的Android取消EditText自动获取焦点默认行为的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 解析XML方式-DOM,SAX
- 下一篇: 8个排序算法的稳定性总结