【发布时间】:2021-05-19 12:58:19
【问题描述】:
我知道
样式指定特定类型视图的属性。例如,一种样式可能指定按钮的属性。您在样式中指定的每个属性都是您可以在布局文件中设置的属性。通过将所有属性提取到一个样式中,可以很容易地跨多个小部件使用和维护它们。
主题定义了一组命名资源,这些资源可以被样式、布局、小部件等引用。主题将语义名称(如 colorPrimary)分配给 Android 资源。
所以,我想我可以从样式文件中设置theme 属性。
为什么这不起作用?
<!-- Customize your theme here. -->
<item name="toolbarStyle">MyToolbarStyle</item>
...
<style name="MyToolBarTheme" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="android:textColorPrimary">@color/white</item>
<item name="colorOnPrimary">@color/white</item>
</style>
<style name="MyToolbarStyle" parent="Widget.AppCompat.Toolbar">
<item name="theme">@style/MyToolBarTheme</item>
</style>
相反,这可以正常工作:
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/homeToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/MyToolBarTheme" />
【问题讨论】:
标签: android material-design android-theme