gpt4 book ai didi

android - 如何在空的edittext上更改 Material TextInputLayout提示颜色?

转载 作者:行者123 更新时间:2023-12-04 23:49:39 25 4
gpt4 key购买 nike

我正在尝试更改 TextInputLayout 提示颜色,以防它为空且未聚焦但我不能这样做,这是我的布局

<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)
}

关于android - 如何在空的edittext上更改 Material TextInputLayout提示颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70080895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com