AndroidThemeManger is a theme manager for Android:
- Apply theme at runtime
- Support multiple theme
- Supports night mode
- Api 14+
Add JitPack to repositories in your project's root build.gradle
file:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency to your module's build.gradle
file:
dependencies {
...
implementation 'com.github.MostafaTaghipour:thememanager:1.0.0'
}
- Define app theme (s):
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.NoActionBar.Red">
<item name="colorPrimary">@color/colorPrimary_Red</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark_Red</item>
<item name="colorAccent">@color/colorAccent_Red</item>
</style>
</resources>
- Set app theme like below:
ThemeManager.getInstance().currentTheme = R.style.AppTheme_NoActionBar_Red
ThemeManager.getInstance().nightMode = AppCompatDelegate.MODE_NIGHT_YES
- Set activities theme like this:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ThemeManager.getInstance().applyTheme(this)
}
- Thats it, enjoy it
Mostafa Taghipour, mostafa@taghipour.me
AndroidThemeManager is available under the MIT license. See the LICENSE file for more info.