【发布时间】:2015-12-26 00:30:04
【问题描述】:
我在 NavigationDrawer 中使用 TextInputLayout(+ 搜索)。当用户切换此抽屉时,光标焦点立即出现在 TextInputLayout 字段上。
在用户点击之前,是否可以不关注该字段?
谢谢!
【问题讨论】:
-
将它添加到你的 xml android:focusable="false"
标签: android android-design-library
我在 NavigationDrawer 中使用 TextInputLayout(+ 搜索)。当用户切换此抽屉时,光标焦点立即出现在 TextInputLayout 字段上。
在用户点击之前,是否可以不关注该字段?
谢谢!
【问题讨论】:
标签: android android-design-library
我解决了这个问题,只需添加另一个 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>
【讨论】:
在我的情况下,这些答案都没有帮助。我所做的如下:
editText.post(() -> {
textInputLayout.setHintAnimationEnabled(false);
editText.clearFocus();
textInputLayout.setHintAnimationEnabled(true);
});
这从设计支持库 v23 开始可用。
【讨论】:
在你的根视图中使用这个属性:
android:focusableInTouchMode="true"
【讨论】:
把它放在你的 onCreate() 中:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
或将其添加到您的活动条目中的清单中:
android:windowSoftInputMode="stateHidden"
【讨论】: