您的位置:首页 > 移动开发 > Android开发

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

2013-08-01 16:51 453 查看
在项目中,一进入一个页面, EditText默认就会自动获取焦点,很是郁闷,Android 如何让EditText不自动获取焦点?于是搜集整理一番,晒出来和大家分享,希望对你们有所帮助

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

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

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

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

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


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

<?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>



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: