【问题标题】:How to disable immediate focus in TextInputLayout?如何在 TextInputLayout 中禁用即时焦点?
【发布时间】:2015-12-26 00:30:04
【问题描述】:

我在 NavigationDrawer 中使用 TextInputLayout(+ 搜索)。当用户切换此抽屉时,光标焦点立即出现在 TextInputLayout 字段上。

在用户点击之前,是否可以不关注该字段?

谢谢!

【问题讨论】:

标签: android android-design-library


【解决方案1】:

我解决了这个问题,只需添加另一个 EditText 并隐藏它

        <EditText
          android:layout_width="0dp"
          android:layout_height="0dp" />
        <android.support.design.widget.TextInputLayout
            android:id="@+id/NghiPhep_TextInputLayout_GhiChu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:hintTextAppearance="@style/TextHintLabel"
            android:layout_marginTop="5dp"
            android:focusableInTouchMode="true"
            >
            <EditText
                android:id="@+id/NghiPhep_txt_GhiChu"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:backgroundTint="@color/colorPrimaryDark"
                android:hint="Ghi chú"
                android:fontFamily="@font/arial_rounded"
                android:inputType="textMultiLine"
                android:singleLine="false"
                android:textSize="18sp"/>
        </android.support.design.widget.TextInputLayout>

【讨论】:

    【解决方案2】:

    在我的情况下,这些答案都没有帮助。我所做的如下:

    editText.post(() -> {
            textInputLayout.setHintAnimationEnabled(false);
            editText.clearFocus();
            textInputLayout.setHintAnimationEnabled(true);
        });
    

    这从设计支持库 v23 开始可用。

    【讨论】:

      【解决方案3】:

      在你的根视图中使用这个属性:

              android:focusableInTouchMode="true"
      

      【讨论】:

      • 但是你的根视图应该是可聚焦的吗?可能不是:|
      【解决方案4】:

      把它放在你的 onCreate() 中:

      this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
      

      或将其添加到您的活动条目中的清单中:

      android:windowSoftInputMode="stateHidden"
      

      【讨论】:

      • 如果您在 textInputLayout 中将文本设置为该 EditText,则无法正常工作
      猜你喜欢
      • 1970-01-01
      • 2021-04-06
      • 1970-01-01
      • 2018-11-23
      • 2011-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-14
      相关资源
      最近更新 更多