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,不会显示的,但是会抢走焦点

  • 相关阅读:
    《信息安全系统设计基础》实验一 开发环境的熟悉
    20145208 《信息安全系统设计基础》第七周学习总结
    20145208 《信息安全系统设计基础》第六周学习总结
    TCP基本概念
    UNP学习笔记1——基本TCP套接字编程
    C++内存分配方式——小结
    APUE学习笔记7——进程间通信
    哈希表的概念和简单的实现算法
    APUE学习笔记6——线程和线程同步
    C++面向对象的设计思想——小结
  • 原文地址:https://www.cnblogs.com/wi100sh/p/5044568.html
Copyright © 2011-2022 走看看