不让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里则不行

优质内容筛选与推荐>>
1、第一周小结
2、anaconda使用,jupyter notebook的使用方法
3、MySQL 之 MHA + ProxySQL + keepalived 实现读写分离,高可用(三)
4、csp-s模拟测试51(b)attack,tree题解
5、PyCharm关闭按两次Shift进入搜索框的功能


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号