繁体   English   中英

在清单中将主题更改为默认主题

[英]Changing theme from default in the manifest

我在Play商店中有一个应用: Just Notes

我最近在应用程序中添加了主题。 问题是,状态栏颜色和默认背景颜色始终默认为清单中提到的主题。

所有其他主题中都提到了colorPrimaryDark,但Android只是在运行时不使用它来设置状态栏颜色。

如何正确覆盖清单中提到的主题

例如。 以下是我的风格

 <style name="AppBaseThemeDark" parent="Theme.AppCompat"> <item name="colorPrimary">@color/primary_material_dark</item> <item name="colorPrimaryDark">@color/primary_dark_material_dark</item> <item name="colorAccent">@color/accent_material_dark</item> <item name="android:textColor">@color/abc_primary_text_material_dark</item> <item name="android:windowNoTitle">true</item> <item name="windowActionBar">false</item> </style> <style name="AppBaseThemeLight" parent="Theme.AppCompat.Light"> <item name="colorPrimary">@color/primary_material_light</item> <item name="colorPrimaryDark">@color/primary_dark_material_light</item> <item name="colorAccent">@color/accent_material_light</item> <item name="android:textColor">@color/abc_primary_text_material_light</item> <item name="android:windowNoTitle">true</item> <item name="windowActionBar">false</item> </style> 

以下是我的清单

 <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppThemeDark" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 

清单中的应用程序主题设置为黑暗。

在我的活动中,这就是我基于共享首选项中保存的内容设置主题的方式。

switch (mPrefs.getInt("theme", -1)) {
    case 0:
        setTheme(R.style.AppThemeDark);
        break;
    case 1:
        setTheme(R.style.AppThemeLight);
        break;
    default:
        //keep the theme from the manifest.
}

如果用户选择了浅色主题,则状态栏和背景仍然保持黑色。

如果我将清单中的主题更改为AppBaseThemeLight,则即使对于深色主题,状态栏也将保持灰色。

由于这仅适用于棒棒糖,因此我使用自定义属性对其进行了修复,以根据主题设置背景。

对于状态栏颜色,我使用了

getWindow()。setStatusBarColor(getResources()。getColor());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM