Android中的EditView如何不默认获取焦点弹出软键盘,点击EditView后会弹出?

本文介绍了解决Android应用中EditText控件自动弹出软键盘的问题。通过设置父布局的焦点属性,可以避免软键盘在Activity启动时自动弹出,从而提升用户体验。

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

情况是这样的:我的一个activity里面有个EditView控件,每次进入到那个界面,就会自动弹出软键盘出来,这样体验感就会很差。应该进去之后不会自动弹出来软键盘,等用户自己点击了EditView再弹出软键盘来。


解决方法:

方法一、在其父控件下,添加如下的属性,就可以完美解决:

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

例如:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/img_area_pic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:src="@drawable/ic_launcher" />

    <EditText
        android:id="@+id/et_area_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:background="@null"
        android:hint="房间名"
        android:inputType="text"
        android:maxLength="6" />

    <Space
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:text="点击名称或图标可进行修改"
        android:textColor="@color/add_title_text_color" />
</LinearLayout>
实测方法一(可能还有其他方法,后续更新)可用,记住是父布局


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值