我正在尝试更改TextInputLayout提示颜色,以防它是edittext空的并且没有焦点,但我做不到,这是我的布局
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_layout"
style="@style/text_material_input_hint_neutral_80_normal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="17dp"
android:layout_marginTop="26dp"
android:layout_marginEnd="17dp"
android:layout_marginBottom="24dp"
android:hint="@string/store_url"
android:textColorHint="@color/neutral_80"
app:boxBackgroundColor="@color/neutral_10"
app:boxCornerRadiusBottomEnd="8dp"
app:boxCornerRadiusBottomStart="8dp"
app:boxCornerRadiusTopEnd="8dp"
app:boxCornerRadiusTopStart="8dp"
app:boxStrokeWidth="0dp"
app:boxStrokeWidthFocused="0dp"
app:hintTextColor="@color/neutral_80"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edittext"
style="@style/text_material_input_text_neutral_130_normal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="test string"
android:paddingStart="12dp"
android:paddingTop="24dp"
android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>
这是我用过的
<style name="text_material_input_hint_neutral_80_normal" parent="TextAppearance.AppCompat">
<item name="android:textSize">12sp</item>
<item name="android:textAllCaps">false</item>
<item name="android:includeFontPadding">false</item>
<item name="android:textColor">@color/neutral_80</item>
</style>
<style name="text_material_input_text_neutral_130_normal" parent="TextAppearance.AppCompat">
<item name="android:textSize">14sp</item>
<item name="android:colorAccent">@color/secondary_80</item>
<item name="android:textAllCaps">false</item>
<item name="android:includeFontPadding">false</item>
<item name="android:textColor">@color/neutral_130</item>
<item name="colorControlActivated">@color/secondary_80</item>
</style>
我正在使用colorControlActivated,正如一些答案在类似的情况下建议的那样,还有android:colorAccent,但这没有帮助?
在编辑文本为空且未聚焦的情况下,如何应用不同的提示颜色?
调用函数的顺序非常重要。
binding.txtLoginInputLayout.apply {
defaultHintTextColor = ContextCompat.getColorStateList(context, R.color.blue)
hintTextColor = ContextCompat.getColorStateList(context, R.color.red)
}
binding.edtLoginInputLayout.apply {
setTextColor(
ContextCompat.getColorStateList(
context,
R.color.green
)
)
highlightColor = ContextCompat.getColor(context, R.color.green_light)
}