12

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

我在AndroidManifest.xml文件中声明了windowSoftInputModeto :"stateVisible"

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

我已遵循此文档

结果:

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

在运行 Android API 28 的设备上,未显示键盘。

它是 Android Pie 中的错误吗?

有什么建议吗?

4

6 回答 6

26

似乎在 Android Pie (API 28) 中,它没有EditText自动设置请求焦点。

因此,您必须以requestFocus编程EditText方式或在 XML 文件中设置。

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();
于 2018-08-21T14:13:57.167 回答
1

对于 Android Pie,我也确实遇到了这个问题。.requestFocus()对我不起作用。

我的问题的解决方案:

确保您EditText的实际可见。我将用作隐藏字段,仅在将宽度和高度设置为toEditText后才显示键盘。01dp

于 2018-11-29T15:26:28.907 回答
1

如果您使用宽度和高度为 0dp 的隐藏 EditText,它将无法在 API 28 饼图上运行,我可以通过将尺寸设置为 1dp 并将小部件的所有部分设置为透明来使其工作。这对我有用:

<EditText
        android:id="@+id/hacked_edit_text"
        android:layout_width="1dp"
        android:layout_height="1dp"
        android:background="@android:color/transparent"
        android:cursorVisible="false"
        android:textColor="@android:color/transparent" />
于 2018-12-17T17:06:02.190 回答
0

我的问题在于设备键盘设置。语言和输入默认键盘,并在我的情况下将其更改为您的设备键盘三星。

在此处输入图像描述

于 2019-08-18T12:41:50.250 回答
0

它在官方文档中有很好的记录:

fun showSoftKeyboard(view: View) {
    if (view.requestFocus()) {
        val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
    }
}
于 2019-10-14T19:48:48.550 回答
-4
<activity
    android:name=".activities.EmailLoginActivity"
    android:launchMode="singleTask"
    android:screenOrientation="portrait"   
    android:windowSoftInputMode="stateVisible|adjustResize" />

希望这可以帮助你

于 2018-08-21T13:22:17.877 回答