在 Android Pie (API-28) 中进入活动时不显示键盘 [英] Keyboard doesn't show up when enter to activity in Android Pie (API-28)

查看:21
本文介绍了在 Android Pie (API-28) 中进入活动时不显示键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在进入电子邮件登录屏幕时弹出设备键盘.

I want to pop up the device keyboard when I enter to Email Login screen.

我在 AndroidManifest.xml 文件中将 windowSoftInputMode 声明为 "stateVisible":

I declared the windowSoftInputMode to "stateVisible" in the AndroidManifest.xml file:

<activity
        android:name=".activities.EmailLoginActivity"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"   
        android:windowSoftInputMode="stateVisible" />

我已遵循此文档.

结果:

在运行 Android API 最多 27 的设备上,会显示键盘.

On devices that run Android API up to 27, the keyboard is shown.

在运行 Android API 28 的设备上,不显示键盘.

On devices that run the Android API 28, the keyboard is not shown.

这是 Android Pie 中的错误吗?

Is it a bug in Android Pie?

有什么建议吗?

推荐答案

似乎在 Android Pie (API 28) 中,它不会自动在 EditText 中设置请求焦点.

Seems in Android Pie (API 28), it is not setting request focus in EditText automatically.

因此,您必须以编程方式或在 XML 文件中设置 EditTextrequestFocus.

So you have to set the requestFocus of your EditText either programmatically or in the XML file.

your_layout.xml

<EditText
        android:id="@+id/et_email"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/_20sdp"
        android:inputType="textEmailAddress"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <requestFocus />
    </EditText>

your_activity.java

findViewById(R.id.et_email).requestFocus();

这篇关于在 Android Pie (API-28) 中进入活动时不显示键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆