MDThemeKit :主题切换工具类 - SheTieJun/BaseKit GitHub Wiki
基于material - MD的颜色系统做主题切换
可以使用下面的工具进行生成主题 https://www.figma.com/community/plugin/1034969338659738588
效果如下:
比如:
-
示例:themes_green.xml : R.style.Base_Theme_LF_Green
如果你使用上面的颜色标准进行设计APP,后面想要切换主题,那么就可以使用这个工具类进行切换
MDThemeKit.startInit(context, listOf(
ThemeBean(R.style.BaseTheme_MD3, "默认主题-跟随系统"),
ThemeBean(R.style.BaseTheme_MD3, "默认主题-黑夜", AppCompatDelegate.MODE_NIGHT_YES),
ThemeBean(R.style.BaseTheme_MD3, "默认主题-日间", AppCompatDelegate.MODE_NIGHT_NO),
ThemeBean(R.style.Base_Theme_LF_Green, "春色宜人(GREEN)", AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY),
ThemeBean(R.style.Base_Theme_LF_RED, "红红火火(RED)", AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY),
))
MDThemeKit.showChangeThemeDialog(fragmentActivity)
fun updateTheme(theme: ThemeBean)
fun updateThemeByType(@StyleRes style: Int, name: String,@NightMode nightMode: Int = AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY)
MD3ThemeKit.updateThemeByType(style.BaseTheme_MD3, "默认主题-跟随系统11")
val isDark: Boolean
fun getCurrentTheme(): SingleLiveEvent<ThemeBean>
fun clearTheme()
fun getThemeList(): ArrayList<ThemeBean>
fun getThemeTitleList(): List<String>
fun getThemeByWhich(which: Int): ThemeBean
fun getThemeNameByWhich(which: Int): String
fun getNightModeByWhich(which: Int): Int
fun getIndexByTheme(theme: ThemeBean)
fun updateTheme(theme: ThemeBean)
fun updateTheme(@StyleRes style: Int, name: String,@NightMode nightMode: Int = AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY)
fun applyThemeOverlay(context: Context, @StyleRes theme: Int)
那就是如果APP的闪图界面使用了Theme.SplashScreen.IconBackground
将无法修改,
因为postSplashScreenTheme被固定了
<style name="App.SplashScreen" parent="Theme.SplashScreen.IconBackground">
<item name="windowSplashScreenAnimatedIcon">@drawable/unsplash_cat1</item>
<item name="windowSplashScreenBackground">@color/white</item>
<item name="windowSplashScreenIconBackgroundColor">@color/white</item>
<!-- must be set-->
<item name="postSplashScreenTheme">@style/BaseTheme.MD3</item>
</style>