下划线、光标和提示在焦点上的 TextInputLayout 中的 TextInputEditText 处消失
Underline, cursor and hint disappeared at TextInputEditText in TextInputLayout on focus
-
android
-
android-appcompat
-
android-textinputlayout
-
android-textinputedittext
-
material-components-android
我有一个带有一堆 TextInputEditText 的编辑配置文件屏幕。之前还可以,现在焦点上的下划线、光标和提示都看不见了。
有人遇到过同样的问题吗?
...
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilFirstName"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/ivContactIcon"
app:layout_constraintEnd_toEndOf="@id/gEnd"
app:layout_constraintTop_toBottomOf="@id/toolbar"
android:layout_marginStart="@dimen/margin_32"
android:layout_marginTop="@dimen/margin_24"
android:hint="@string/profile_edit_hint_first_name"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etFirstName"
android:layout_height="wrap_content"
style="@style/FontRoboRegularSizeMFontPrimaryOneLineMatchWrap"
tools:text="Oleh"
android:inputType="textCapWords"
android:maxLines="1"
android:nextFocusForward="@id/etLastName"
android:imeOptions="actionNext"
/>
</com.google.android.material.textfield.TextInputLayout>
...
更新:
更改根元素的背景后,很明显这些元素变成了白色。没有消失。
TextInputLayout
使用的默认样式是
<style name="Widget.MaterialComponents.TextInputLayout.FilledBox" parent="Base.Widget.MaterialComponents.TextInputLayout">
<!-- underline color in FilledBox style -->
<item name="boxStrokeColor">@color/mtrl_filled_stroke_color</item>
<!-- The color of the label when it is collapsed and the text field is active -->
<item name="hintTextColor">?attr/colorPrimary</item>
....
</style>
mtrl_filled_stroke_color
基于colorOnSurface
。
检查您的主题 colorPrimary
和 colorOnSurface
值,或使用具有上述相同属性的自定义样式。
如果您像我一样苦苦挣扎并且上述解决方案不起作用,则可能是您的项目主题设置了白色主色。
要解决此问题,您可以为您的 TextEdit 创建自定义样式并将其应用于每个:
styles.xml:
<style name="AppThemeCorrectPrimaryColor" parent="AppTheme">
<item name="colorPrimary">@color/notAWhiteColor</item>
</style>
编辑文本:
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppThemeCorrectPrimaryColor"
/>
我为 TextInputLayout
创建了样式并定义了 colorControlActivated
就像
<style name="Widget.AppTheme.TextInputLayout.FilledBox.Dense" parent="Widget.MaterialComponents.TextInputLayout.FilledBox.Dense">
<item name="hintTextColor">@color/black</item>
<item name="boxBackgroundColor">@color/greyLight</item>
<item name="boxStrokeWidth">0dp</item>
<item name="colorControlActivated">@color/orange</item>
</style>
并在 TextInputLayout
上使用主题而不是样式
<com.google.android.material.textfield.TextInputLayout
android:theme="@style/Widget.AppTheme.TextInputLayout.FilledBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
android
android-appcompat
android-textinputlayout
android-textinputedittext
material-components-android
我有一个带有一堆 TextInputEditText 的编辑配置文件屏幕。之前还可以,现在焦点上的下划线、光标和提示都看不见了。
有人遇到过同样的问题吗?
...
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilFirstName"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/ivContactIcon"
app:layout_constraintEnd_toEndOf="@id/gEnd"
app:layout_constraintTop_toBottomOf="@id/toolbar"
android:layout_marginStart="@dimen/margin_32"
android:layout_marginTop="@dimen/margin_24"
android:hint="@string/profile_edit_hint_first_name"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etFirstName"
android:layout_height="wrap_content"
style="@style/FontRoboRegularSizeMFontPrimaryOneLineMatchWrap"
tools:text="Oleh"
android:inputType="textCapWords"
android:maxLines="1"
android:nextFocusForward="@id/etLastName"
android:imeOptions="actionNext"
/>
</com.google.android.material.textfield.TextInputLayout>
...
更新: 更改根元素的背景后,很明显这些元素变成了白色。没有消失。
TextInputLayout
使用的默认样式是
<style name="Widget.MaterialComponents.TextInputLayout.FilledBox" parent="Base.Widget.MaterialComponents.TextInputLayout">
<!-- underline color in FilledBox style -->
<item name="boxStrokeColor">@color/mtrl_filled_stroke_color</item>
<!-- The color of the label when it is collapsed and the text field is active -->
<item name="hintTextColor">?attr/colorPrimary</item>
....
</style>
mtrl_filled_stroke_color
基于colorOnSurface
。
检查您的主题 colorPrimary
和 colorOnSurface
值,或使用具有上述相同属性的自定义样式。
如果您像我一样苦苦挣扎并且上述解决方案不起作用,则可能是您的项目主题设置了白色主色。
要解决此问题,您可以为您的 TextEdit 创建自定义样式并将其应用于每个:
styles.xml:
<style name="AppThemeCorrectPrimaryColor" parent="AppTheme">
<item name="colorPrimary">@color/notAWhiteColor</item>
</style>
编辑文本:
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppThemeCorrectPrimaryColor"
/>
我为 TextInputLayout
创建了样式并定义了 colorControlActivated
就像
<style name="Widget.AppTheme.TextInputLayout.FilledBox.Dense" parent="Widget.MaterialComponents.TextInputLayout.FilledBox.Dense">
<item name="hintTextColor">@color/black</item>
<item name="boxBackgroundColor">@color/greyLight</item>
<item name="boxStrokeWidth">0dp</item>
<item name="colorControlActivated">@color/orange</item>
</style>
并在 TextInputLayout
<com.google.android.material.textfield.TextInputLayout
android:theme="@style/Widget.AppTheme.TextInputLayout.FilledBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>