Android屏蔽EditTex获得焦点

本文介绍了一种解决新屏幕中搜索功能导致键盘自动弹出问题的方法,通过为父控件设置特定属性来避免键盘自动弹出,提高用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景:给新屏幕添加了一个搜索的功能,但是一进入屏幕就弹出键盘,影响用户操作。


原理:使EditText失去焦点,禁止弹出键盘。


方法:在其父控件添加如下属性。

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


举例:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll_search"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:focusable="true"
        android:focusableInTouchMode="true" >

        <EditText
            android:id="@+id/edt_search"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="@string/str_input_hint"
            android:paddingLeft="10dp"
            android:paddingRight="20dp"
            android:singleLine="true" />

        <ImageView
            android:id="@+id/iv_delete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/delete" />
    </RelativeLayout>

    <Button
        android:id="@+id/btn_search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/str_search" />
</LinearLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值