• Android 如何让EditText不自动获取焦点


    在项目中,一进入一个页面, EditText默认就会自动获取焦点。

    那么如何取消这个默认行为呢?

    在网上找了好久,有点 监听软键盘事件,有点 调用 clearFouse()方法,但是测试了都没有! xml中也找不到相应的属性可以关闭这个默认行为

    解决之道:在EditText的父级控件中找一个,设置成

       android:focusable="true"  
       android:focusableInTouchMode="true"

    这样,就把EditText默认的行为截断了!

    <LinearLayout 
            style="@style/FillWrapWidgetStyle"
            android:orientation="vertical"
            android:background="@color/black"
            android:gravity="center_horizontal"
            
            android:focusable="true"  
            android:focusableInTouchMode="true"
            >
            <ImageView
                android:id="@+id/logo"
                style="@style/WrapContentWidgetStyle"
                android:background="@drawable/dream_dictionary_logo"
              />
            <RelativeLayout 
                style="@style/FillWrapWidgetStyle"
                android:background="@drawable/searchbar_bg"
                android:gravity="center_vertical"
                >
                <EditText
                    android:id="@+id/searchEditText"
                   style="@style/WrapContentWidgetStyle"
                   android:background="@null"
                   android:hint="Search"
                   android:layout_marginLeft="40dp"
                   android:singleLine="true"
                 />
                
            </RelativeLayout>
            
        </LinearLayout>

  • 相关阅读:
    编辑文章
    POJ_1195 Mobile phones 【二维树状数组】
    WCF探索之旅(三)——IIS公布WCF服务
    doT.js具体使用介绍
    数据结构:最小生成树--Kruskal算法
    关于打开sdk下载不了的最优秀解决方式
    JS 之 数据类型转换
    MongoDB学习笔记&lt;六&gt;
    Spring、Hibernate 数据不能插入到数据库问题解决
    Cocos2d-x 3.0final 终结者系列教程16-《微信飞机大战》实现
  • 原文地址:https://www.cnblogs.com/error404/p/2837294.html
Copyright © 2020-2023  润新知