【发布时间】:2018-05-21 12:39:08
【问题描述】:
我需要在活动开始时移除或阻止焦点,并且我使用了一些代码,例如:
android:focusableInTouchMode="true"
android:windowSoftInputMode="stateHidden"
但总是在开始时将焦点放在第一个 TextInputLayout 没有键盘
【问题讨论】:
标签: java android focus android-textinputlayout
我需要在活动开始时移除或阻止焦点,并且我使用了一些代码,例如:
android:focusableInTouchMode="true"
android:windowSoftInputMode="stateHidden"
但总是在开始时将焦点放在第一个 TextInputLayout 没有键盘
【问题讨论】:
标签: java android focus android-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">
【讨论】:
只需添加 -
<View
android:layout_width="0px"
android:layout_height="0px"
android:focusableInTouchMode="true" />
在 EditText 上方的 xml 文件中,它将完成工作。
【讨论】:
试试这个
添加这些行
android:focusable="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">
【讨论】: