Introduction
There may be situations where the entire look of the screen (current activity) needs to be changed as a result of some event. The event may be as simple as a button click, or may be a sensor feedback, or even as a result of streaming data from internet.
Many articles explain how to set a theme in android manifest file, during design time. However, doing this will result in the application/activity itself starting with the theme and not as a response to an "event".
The Finished Demo
Repository Link
https://github.com/gopalnair/Android-Style-DemoKey Points On Code
In method MainActivity.onCreate , make sure the setTheme() is called BEFORE call to parent. In this example, when the activity starts for the first time from launcher, there are no extras in the launcher intent. Hence, application start with default theme applied.
However, when user clicks on one of the "Style" buttons, we call the SAME activity (MainActivity), and package the target theme information in intent extras like so:
No comments:
Post a Comment