材料组件无法更改颜色

时间:2018-11-14 19:34:14

标签: android android-layout material-design material-ui

请尝试解决此问题两天,但未成功

我对新的材料设计组件有疑问

我使用了样式Widget.MaterialComponents.TextInputLayout.OutlinedBox

我尝试获得此结果。.(不更改主题颜色)仅xml或代码

enter image description here

我的实际小部件.. :(

enter image description here

我的主题

Theme.MaterialComponents.Light.NoActionBar.Bridge

组件的xml代码

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/core_text"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        style="@style/TextInputLayout"
        app:errorEnabled="true"
        android:layout_weight="9">

    <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/name_edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            tools:hint="Trip name"/>

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

样式

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

<style name="HintText" parent="TextAppearance.MaterialComponents.Subtitle2">
    <item name="android:textColor">?secondaryVariant</item>
</style>

我尝试了互联网上的所有内容,但我不知道哪里出了问题。谢谢你的帮助

在gradle中,我具有所有最新版本的库和构建版本

如果邹想写其他信息。

感谢您的帮助

2 个答案:

答案 0 :(得分:1)

<style name="TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
        <item name="colorAccent">@color/HintText</item>
</style>

 <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/core_text"
        style="@style/TextInputLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="9"
        android:theme="@style/TextInputLayout"
        app:errorEnabled="true">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/name_edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            tools:hint="Trip name" />
 </com.google.android.material.textfield.TextInputLayout>

此外,如果您需要更改框笔划,则需要覆盖默认颜色

<color name="colorTextInputStroke">#CCD1D3</color>
<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">
        @color/colorTextInputStroke
</color>

答案 1 :(得分:0)

此问题可以通过自定义主题中的此行解决

   <item name="colorPrimary">?secondary</item>
   <item name="colorPrimaryDark">?secondaryVariant</item>
   <item name="colorOnPrimary">?onSecondaryH</item>
   <item name="colorSecondary">?primary</item>
   <item name="colorOnSecondary">?onPrimaryH</item>
相关问题