Member-only story
Change Android Theme Programmatically
Sometime we want to change theme based on menu that we click.. so to make it easy.. you can change theme programmatically? How to do it?
There is some ways to do it.. but the best what i know is by override getTheme method in Activity…
override fun getTheme(): Resources.Theme {
val theme = super.getTheme()
when (intent.getStringExtra(KEY_THEME)) {
BLUE -> {
theme.applyStyle(R.style.BlueTheme, true)
}
GREEN -> {
theme.applyStyle(R.style.GreenTheme, true)
}
ORANGE -> {
theme.applyStyle(R.style.OrangeTheme, true)
}
}
return theme
}This is just an example when we change Theme based on data that we send to this Activity..
Befit of using this code make Fragment it also have the same Theme.. Let’s try..
I looked at all types of sustenance, but did not find a better sustenance than patience. — Umar Ibn Al Khattab








