【问题标题】:Prevent Focus onCreate Activity防止专注于创建活动
【发布时间】:2018-05-21 12:39:08
【问题描述】:

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

android:focusableInTouchMode="true"

android:windowSoftInputMode="stateHidden"

但总是在开始时将焦点放在第一个 TextInputLayout 没有键盘

【问题讨论】:

    标签: java android focus android-textinputlayout


    【解决方案1】:

    试试这个

    在清单文件中使用 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">
    

    【讨论】:

      【解决方案2】:

      只需添加 -

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

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

      【讨论】:

        【解决方案3】:

        试试这个

        添加这些行

        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">
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-10-27
          • 1970-01-01
          • 2020-12-31
          • 1970-01-01
          • 2015-08-17
          • 1970-01-01
          • 2020-05-29
          • 1970-01-01
          相关资源
          最近更新 更多