【问题标题】:How to change FloatingPlaceholderColor but not hint color in textinputlayout in android如何在android的textinputlayout中更改FloatingPlaceholderColor但不提示颜色
【发布时间】:2020-07-02 06:21:36
【问题描述】:

我已经创建了带有提示的 TextInputLayout(OutlinedBox)。预计以 3 色显示。

  1. 当占位符聚焦时,“浮动标签”应以颜色 1(黄色)显示
  2. 当占位符未聚焦时,“提示”应以颜色 2(灰色)显示
  3. 当占位符未聚焦时,“浮动标签”应显示为彩色(蓝色)

但是,未聚焦的“提示”和未聚焦的“浮动标签”始终采用与在占位符中指定的颜色相同的颜色(在这种情况下,颜色为 2-灰色)。

这里我使用了依赖com.google.android.material:material:1.2.0-alpha05

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/tv_mb_text_layout3"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@id/tv_mb_text_layout2"
        app:layout_constraintLeft_toLeftOf="parent"
        style="@style/MBFormTextInputStyle"
        android:hint="label_text"
        app:errorEnabled="true">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:text="Priyanka"
            android:layout_height="wrap_content"/>

    </com.google.android.material.textfield.TextInputLayout>

    <!-- Style for Hint -->
    <style name="hint_appearance" parent="TextAppearance.AppCompat">
        <item name="android:textSize">8sp</item>
        <item name="android:textColor">@android:color/holo_orange_dark</item>
    </style>

    <style name="MBFormTextInputStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
        <item name="errorTextAppearance">@style/error_a`enter code here`ppearance</item>
        <item name="errorTextColor">@android:color/holo_purple</item>
        <item name="boxStrokeErrorColor">@android:color/holo_purple</item>
        <item name="hintTextAppea`enter code here`rance">@style/hint_appearance</item>
        <item name="hintTextColor">@android:color/holo_blue_dark</item>
        <item name="android:textColorHint">@android:color/holo_purple</item>
    </style>

【问题讨论】:

    标签: android android-layout material-design android-styles android-textinputlayout


    【解决方案1】:

    如果你 ctrl+点击style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu" 它将带您到values.xml 文件。在那里您将看到所有默认颜色,如下所示

    ....
    ....
     <color name="mtrl_textinput_default_box_stroke_color">#6B000000</color>
        <color name="mtrl_textinput_disabled_color">#1F000000</color>
        <color name="mtrl_textinput_filled_box_default_background_color">#0A000000</color>
        <color name="mtrl_textinput_focused_box_stroke_color">#00000000</color>
        <color name="mtrl_textinput_hovered_box_stroke_color">#DE000000</color>
    ....
    ....
    

    选择您想要更改的合适颜色并在colors.xml 文件中覆盖它。就是这样

    【讨论】:

      猜你喜欢
      • 2015-09-15
      • 1970-01-01
      • 2020-06-05
      • 1970-01-01
      • 2020-06-26
      • 2015-08-29
      • 2022-01-01
      • 2015-08-15
      相关资源
      最近更新 更多