zoukankan      html  css  js  c++  java
  • 【转】android去掉EditView的默认焦点问题

    原文网址:http://www.111cn.net/sj/android/54680.htm

    做一个输入框时发现android中EditView的默认焦点了,这种问题如果是在输入框还好,但在搜索页面或浏览页面这样就会影响用户体验了,那要如何取消EditView的默认焦点呢,下面我们来看看。

    在网上找了好久,有点 监听软键盘事件,有点 调用 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>

    查阅了很多资料后,发现以下方法最简单:

    在xml中,在EditText控件之前
    加入

     代码如下 复制代码

    <LinearLayout
        android:id="@+id/linearLayout_focus"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_width="0px"
        android:layout_height="0px"/>

    这是一个虚假的LinearLayout,不会显示的,但是会抢走焦点

  • 相关阅读:
    命令用法示例
    Elastic:用Docker部署Elastic栈
    Elastic:使用Heartbeat进行Uptime监控
    Elastic:如何在一个机器上同时模拟多个node
    Elastic 使用索引生命周期管理实现热温冷架构
    Logstash:运用jdbc_streaming来丰富我们的数据
    Logstash:多个配置文件(conf)
    Logstash:处理多个input
    使用 Logstash 和 JDBC 确保 Elasticsearch 与关系型数据库保持同步
    Logstash:把MySQL数据导入到Elasticsearch中
  • 原文地址:https://www.cnblogs.com/wi100sh/p/5044568.html
Copyright © 2011-2022 走看看