【问题标题】:Material TexInputLayout change color [duplicate]材质 TexInputLayout 更改颜色 [重复]
【发布时间】:2020-09-22 04:46:07
【问题描述】:

我需要更改颜色,但我不知道该怎么做。你能帮帮我吗?

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/contraseña"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginTop="440dp"
    android:layout_marginEnd="16dp"

    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Contraseña"
        android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>

enter image description here

我想把灰色改成白色。

【问题讨论】:

  • 你想换什么颜色?
  • 我想把边框和提示文字改成白色

标签: android android-studio android-layout


【解决方案1】:

对于更改边框颜色和hintTextColor,您可以使用

app:boxStrokeColor="your color"
app:hintTextColor="your color" /*This changes the color of hint when it's collapsed 
and moved to top that's when user enters a character.*/
app:textColorHint="your color" //This is the text color of uncollapsed hint that's the default state.

此外,如果您想创建一种样式,那么这是我使用的完整样式,您可以根据需要进行修改。

<style name="TextInputLayoutAppearanceOutLined" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
    <item name="hintTextAppearance">@style/HintText</item>
    <item name="helperTextTextAppearance">@style/HelperText</item>
    <item name="counterTextAppearance">@style/HelperText</item>

    <item name="android:textColor">@color/dark_grey</item>
    <item name="android:textColorHint">@color/dark_grey</item>
    <item name="hintTextColor">@color/colorAccent</item>
    <item name="boxStrokeColor">@color/colorAccent</item>
    <item name="startIconTint">@color/colorAccent</item>
    <item name="endIconTint">@color/colorAccent</item>
    <item name="boxBackgroundColor">@color/white</item>

    <item name="boxCornerRadiusBottomEnd">10dp</item>
    <item name="boxCornerRadiusBottomStart">10dp</item>
    <item name="boxCornerRadiusTopEnd">10dp</item>
    <item name="boxCornerRadiusTopStart">10dp</item>

    <item name="boxStrokeWidthFocused">2dp</item>


    <item name="hintEnabled">true</item>
    <!--<item name="hintAnimationEnabled">true</item>-->

</style>

这些是改变 HelperText 或 HintText 外观的样式元素:

<style name="HintText" parent="TextAppearance.Design.Hint">
    <item name="android:textSize">12sp</item>
</style>

<style name="HelperText" parent="TextAppearance.Design.HelperText">
    <item name="android:textSize">12sp</item>
</style>

并将其设置为TextInputlayoutstyle="@style/TextInputLayoutAppearanceOutLined"。无论样式中提到什么,您也可以在 XML 布局标签中使用它。

此外,Material 的官方文档TextInputLayout 非常重要且易于理解,不像 Android 的开发者文档,您应该阅读它们以了解更多信息here

【讨论】:

  • 非常感谢!它有效
  • @Jorge 很高兴它有帮助。
猜你喜欢
  • 2019-09-26
  • 1970-01-01
  • 2021-11-08
  • 2017-05-20
  • 2015-01-06
  • 2022-01-12
  • 2019-04-17
  • 2020-08-15
  • 1970-01-01
相关资源
最近更新 更多