【发布时间】:2020-06-12 06:04:03
【问题描述】:
大家好,我是 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 material-design android-theme android-textinputlayout material-components