欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > Android打开Activity时不自动弹出键盘

Android打开Activity时不自动弹出键盘

2024/10/24 5:18:17 来源:https://blog.csdn.net/u013076551/article/details/143001826  浏览:    关键词:Android打开Activity时不自动弹出键盘

背景

在一个页面有2个EditText输入框,刚进入activity的时候系统默认第一个EditText获得焦点且键盘弹出。

如何修复

这里分2种情况处理。

EditText有光标不弹出键盘

只需要到配置文件增加以下配置即可。

<activity...android:windowSoftInputMode="stateHidden"...>
EditText无光标不弹出键盘

如果想光标也定位在EditText上,可以配合上面的配置,然后在activity的页面的根布局增加以下配置:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:focusable="true"android:focusableInTouchMode="true"android:background="@color/light_grey">

上面是例子:
在配置文件增加:

android:windowSoftInputMode="stateHidden"

且根布局增加

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

即可。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com