防止 Focus onCreate Activity

Prevent Focus onCreate Activity

我需要在 activity 开始时移除或阻止焦点,我使用了一些代码,例如:

android:focusableInTouchMode="true"

android:windowSoftInputMode="stateHidden"

但总是在开始时焦点先进入 TextInputLayout 没有键盘

试试这个

在清单文件中使用android:windowSoftInputMode="stateAlwaysHidden"

并在您的根目录中使用 ConstraintLayout 布局

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

示例代码

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp">

试试这个

添加这些行

android:可聚焦="true" android:focusableInTouchMode="true"

到 xml 中的父布局

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp">

只需添加 -

<View
    android:layout_width="0px"
    android:layout_height="0px"
    android:focusableInTouchMode="true" />

在 EditText 上方的 xml 文件中,它将完成工作。