欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-12-14 18:23:10
在项目中,一进入一个页面, edittext默认就会自动获取焦点。 那么如何取消这个默认行为呢? 在网上找了好久,有点 监听软键盘事件,有点 调用 clearfouse()...
在项目中,一进入一个页面, edittext默认就会自动获取焦点。

那么如何取消这个默认行为呢?
在网上找了好久,有点 监听软键盘事件,有点 调用 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>

上一篇:

下一篇: