如何解决不关注此内容时显示TextInputEditText的标签
我有一个带有两个TextInputEditText
的布局,当我在上面设置一个文本时(以编程方式或使用xml
),然后将焦点放在另一个TextInputEditText
上,上面的标签{{1 }}已隐藏。
我想显示这个标签,即使在其中写了文字。
我的TextInputEditText
代码:
xml
我的风格:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/whiteGray2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:orientation="horizontal"
android:weightSum="2"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp">
<com.google.android.material.textfield.TextInputLayout
style="@style/CustomBorderTextInputEditText"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:hint="@string/oldCount"
app:hintTextColor="@color/gray_text">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/input_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:inputType="none"
android:imeOptions="actionNext"
android:text="Hi How are you"
android:textColor="@color/gray_text"
android:textColorHint="@color/gray_text" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/CustomBorderTextInputEditText"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:hint="@string/newCount">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/newCount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColorHint="@color/gray_text"
android:hint="@string/newCount"
android:textColor="@color/gray_text"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
解决方法
将其添加到您的xml代码中:
android:focusableInTouchMode="true"
或
将其添加到您的Java代码中:
EditText newCount = (EditText)findViewById(R.id.newCount);
newCount.setFocusable(true);
可能对您有用,请尝试一下。
,我找到了答案。我应该添加textColorHint
并设置颜色,而不是添加hintTextColor
属性。但是现在我很困惑,两者之间有什么区别?
您的问题在这里:
<com.google.android.material.textfield.TextInputEditText
android:textColorHint="@color/gray_text"
删除android:textColorHint
中的TextInputEditText
并使用:
<com.google.android.material.textfield.TextInputLayout
app:hintTextColor="@color/colorSecondary"
android:textColorHint="@color/text_input_hint_selector"
hintTextColor
是折叠标签且文本字段处于活动状态时标签的颜色。
android:textColorHint
是所有其他文本字段状态(例如,静止和禁用)中标签的颜色。
只是一个例子:
TextInputLayout
:
已禁用:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。