不让editText自动获取焦点
一个布局里有edittext的话 一加载这个布局 edittext就会自动获取焦点 很烦
之前在网上查了一下 怎么不让edittext自动获取焦点
有位大神写到 在它的父控件上加上这样两个参数:
android:focusable="true"
android:focusableInTouchMode="true"
自己试了一下 确实管用 写上之后edittext就失去焦点了 除非你点击它 要不然它是不会获取焦点的
但是如果我把这两句话写到其他的地方呢?还管用吗?测下
假如我有一个textview和一个edittext 都有自己的父控件 我把这两句话写到textview的父控件里
结果是一样的 edittext同样会失去焦点
经过一番测试后得到结论 只要把这两句话写到任何一个父控件中 edittext都会失去焦点
举个例子:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="aaaaaaaa" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="bbbbbbbbb" /> </LinearLayout> </LinearLayout>
像上面的布局文件里有三个linearlayout
把android:focusable="true"
android:focusableInTouchMode="true"插入到任何一个linearlayout里都会是edittext失去焦点
但是插入到textview里则不行