Reputation: 21
In my app, I have multiple user accounts. Each user can define their own set of colors. Such as colorPrimary
, colorPrimaryDark
, colorAccent
etc. So whenever a user get logged in, the activity will use the user defined colors
for theme
.
For better understanding, say my user
is:
class User {
String user_name = "Iron Man";
int colorPrimary = Color.RED;
int colorAccent = Color.BLUE;
...
Note: User can choose any color. So there will be no predefined themes.
Is it possible to apply theme attributes totally dynamically and only from the code?
Upvotes: 0
Views: 779
Reputation: 4722
I have created the same idea in my two apps, you have two options
The first option, create many themes in your theme.xml file and change the full theme depend on the user using the setTheme function from activity, for example, dark theme, white theme, blue theme...etc like Askfm App
Check this app code, I have created this feature on it https://github.com/amrdeveloper/askme
The second option, give the user the ability to change everything using a color picker and use some functions like getSupportActionBar, setStatusBarColor, setNavigationBarColor, and SharedPreferences to change theme
I have implemented this idea on my app you can check the result from the link
https://play.google.com/store/apps/details?id=com.amrdeveloper.materialtimer
but you can't edit theme XML from the runtime because it immutable
Upvotes: 2