自学内容网 自学内容网

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"

即可。


原文地址:https://blog.csdn.net/u013076551/article/details/143001826

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!