setTheme不会更改工具栏

时间:2019-06-09 17:35:19

标签: android android-layout android-activity android-theme android-styles

我正在尝试使用

更改整个应用程序主题
@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之前的答案,但没有任何改变。

2 个答案:

答案 0 :(得分:0)

尝试将setTheme(..)调用放在super.onCreate(savedInstanceState)之后。

答案 1 :(得分:0)

在我发现您无法覆盖setTheme之后,如果即时通讯使用默认名称,例如(PrimaryColor + PrimaryDarkColor + AccentColor),则在将其更改为 (DefaultPrimary + DefaultPrimaryDark + DefaultAccent

相关问题