当前位置: 移动技术网 > IT编程>移动开发>Android > Android取消EditText自动获取默认焦点

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

宁夏人事考试信息网,龚仁龙老婆,炫火网

最近在通讯录新建联系人=中,一进入一个页面, 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>

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网