为什么我不能通过android:theme更改hintTextAppearance?

问题描述 投票:0回答:1

您好,我是android主题和样式的新手。根据官方文件

样式是指定单个View外观的属性的集合。样式可以指定属性,例如字体颜色,字体大小,背景颜色等等。主题是一种样式类型,已应用于整个应用程序,活动或视图层次结构,而不仅仅是单个视图

但是我不能通过android:theme属性来更改某些属性,但是我可以通过style]来更改

这里有这个样式文件:

<style name="Style.InputLayout" parent="Widget.Design.TextInputLayout">
    <item name="errorTextAppearance">@style/ErrorTextAppearance</item>
    <item name="hintTextAppearance">@style/HintTextAppearance</item>
    <item name="errorEnabled">true</item>
</style>
<style name="HintTextAppearance" parent="TextAppearance.Design.Hint">
    <!-- Inactive and Active label color-->
    <item name="android:textColor">?attr/colorShadow</item>
</style>

<style name="ErrorTextAppearance" parent="TextAppearance.Design.Error">
    <!-- Error text color-->
    <item name="android:textColor">?attr/colorError</item>
</style>

而且我有一个TextInputLayout为:

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/tfUsername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/Style.InputLayout"
        android:hint="Username">
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/Theme.EditText"/>

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

这符合我的预期。但是,当我在TextInputLayout中将style

属性更改为android:theme时,如下所示:
<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/tfUsername"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/Style.InputLayout"
    android:hint="Username">
    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/Theme.EditText"/>

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

它不起作用。为什么会这样?

您好,我是android主题和样式的新手。根据官方文档,样式是指定单个View外观的属性的集合。样式可以指定...

android material-design android-theme android-textinputlayout
1个回答
0
投票

它不起作用。为什么会这样?

© www.soinside.com 2019 - 2024. All rights reserved.