关于打开activity防止弹出输入法(让Edittext失去焦点)

本文介绍了解决Android应用中EditText组件导致的键盘自动弹出问题。通过在父布局中设置focusable属性,可以有效避免键盘不必要的弹出,提高用户体验。

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

有了类似edittext的布局之后,每次打开页面总是会弹出输入法,很影响美观。后来查了网上网友的建议,找到两种方法:1.在edittext的父布局加上android:focusable="true"和

    android:focusableInTouchMode="true"的代码,2.在相同父布局下的相邻布局加上android:focusable="true"和android:focusableInTouchMode="true"代码。一般情况下这两种方法确实有效。但是在一个activity有多个edittext嵌套下,有时候是不管用了,输入法照样弹出来。

经过多次测试,发现在最大父布局中加入android:focusable="true"和android:focusableInTouchMode="true"代码,能很好解决之前不能解决的问题,暂时没有发现输入法弹出的现象。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    tools:context="com.example.dddd.MainActivity" >



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值