【发布时间】:2015-06-15 13:13:28
【问题描述】:
我正在构建一个在运行时加载特定主题的活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
if (shouldLoadLight()) {
setTheme(R.style.ThemeLight);
} else {
setTheme(R.style.ThemeDark);
}
super.onCreate(savedInstanceState);
...
}
使用 Light 主题,工具栏为白色,内容为白色背景。对于深色主题,工具栏为深灰色,内容也为白色背景。 (与 Light.DarkActionBar 旧主题一样)
我需要将自定义主题应用于工具栏以获得良好的触摸反馈颜色,但由于活动主题是动态的,我无法在我的布局 XML 中设置它。
这是我到目前为止所尝试的:
主题.xml
<resources>
<!-- LIGHT -->
<style name="ThemeLight" parent="Theme.AppCompat.Light.NoActionBar">
<!-- here, i want grey ripple, it's provided by the light theme already -->
</style>
<!-- DARK -->
<style name="ThemeDark" parent="Theme.AppCompat.Light.NoActionBar">
<!-- here, i want white ripple, like with the Dark.ActionBar theme -->
<item name="toolbarStyle">@style/ToolbarDark</item> <!-- not working -->
<item name="actionbarTheme">@style/ToolbarDark</item> <!-- not working -->
</style>
<style name="ToolbarDark" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- here, i want white ripple, like with the Dark.ActionBar theme -->
</style>
</resources>
知道如何从 theme.xml 而不是从布局中的android:theme= xml 属性实现这种工具栏样式吗?
非常感谢, 皮埃尔。
【问题讨论】:
-
尝试将样式也应用到您的工具栏。像 Light.DarkActionBar
-
直接在布局的 XML 中?我不能这样做,因为全局主题是动态的,因此,有时我想要工具栏上的 Light.DarkActionBar,有时我只想要 Light...:s
标签: android toolbar android-appcompat