Android取消EditText自动获取默认焦点

发布时间:2020-10-02 14:08:30 作者:ganchuanpu
来源:脚本之家 阅读:683

最近在通讯录新建联系人=中,一进入一个页面, EditText默认就会自动获取焦点,很是郁闷, 如何让EditText不自动获取焦点?

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

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

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

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

demo.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:background="#ffffff" 
 android:baselineAligned="false" 
 android:focusable="true" 
 android:focusableInTouchMode="true" > 
   <RelativeLayout 
    android:layout_width="250dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/txtLayout" 
    android:layout_marginTop="20dp" 
android:layout_centerHorizontal="true" 
    > 
   <EditText 
    android:layout_width="fill_parent" 
    android:layout_height="35dp" 
    android:id="@+id/editPhone" 
    android:phoneNumber="true" 
    android:text="@string/txtaddPhone" 
    android:textColor="#D8D8D8" 
android:background="@drawable/txtupbg" 
    android:textSize="15dp" 
    /> 
   </RelativeLayout> 
</RelativeLayout>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持亿速云!

推荐阅读:
  1. Android 中怎么设置EditText默认不获得焦点
  2. EditText焦点自动带出软键盘问题

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

edittext 焦点 roi

上一篇:python中reader的next用法

下一篇:Linux模拟网络丢包与延迟的方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》