android - setTheme 没有改变工具栏
问题描述
我正在尝试使用更改整个应用程序主题
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme_ONE);
helper = new PreferenceHelper(this);
super.onCreate(savedInstanceState);
}
基本应用程序主题。
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorHint">@color/colorPrimary</item>
<item name="android:actionButtonStyle">@style/MyActionButtonStyle</item>
<item name="android:typeface">serif</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.ONE" parent="AppTheme.NoActionBar">
<item name="colorPrimary">@color/red</item>
<item name="colorPrimaryDark">@color/red_800</item>
<item name="colorAccent">@color/red_100</item>
<item name="android:textColorHint">@color/red_A700</item>
</style>
但工具栏没有任何变化:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:paddingEnd="10dp"
app:popupTheme="@style/AppTheme.PopupOverlay">
或应用程序中使用 colorPrimary 的任何布局。我一直在寻找有关更改清单并将 settheme 放在 super.oncreate 之前的很多答案,但没有任何改变。
解决方案
之后我发现如果我使用默认名称(例如(++))你不能覆盖setTheme,PrimaryColor
它在我将它更改为(PrimaryDarkColor
++ )后工作AccentColor
DefaultPrimary
DefaultPrimaryDark
DefaultAccent
推荐阅读
- php - Laravel 测试商店方法
- kotlin - Gradle 子模块 compileOnly 函数不存在
- php - 如何根据子域(如 wordpress 主题)更改带有文件的根文件夹
- javascript - “满足条件”在编程语言中究竟意味着什么?
- python - 使用多处理在类方法的 while 循环内运行函数
- c# - Specflow - 如何在 C# 中以编程方式从 srprofile 获取目标名称
- apache-spark - 如何通过 Spark Structured Streaming 确保 kafka 数据摄取不丢失数据?
- r - 在 R 中针对最大深度(从 1 到 20)绘制 R² 值
- julia - 默认项目中的包
- openpose - 找不到模块:tensorflow.contrib