1

I'm making an Android application using Kotlin. It contains App Theme color list so the user can select one color from it, and then I save this color in Shared Preferences.

I've done with all Shared Preferences and XML values stuff, and I've succeeded to change the theme smoothly in the settings activity, and when I reopen the application I find the saved color successfully in settings activity.

The problem is: the changes happens on settings activity only, not in the whole app, and if I want to affect all activities I should use setTheme() in each activity's onCreat(). I don't want to do that since my application has many activities.

Is there better approach to achieve that.

I tried to call setTheme() method on Application class, but it doesn't work.

1 Answer 1

0

I understand that you don't want to do it in every Activity, but with activities there is no other approach than setting theme in each one of them.

I would suggest you to create abstract parent e.g. BaseActivity and call setTheme() here inside onCreate(). Then you will update your activities just to extend the BaseActivity and make sure you are calling super.onCreate().

It's faster then pasting the code in every activity individually and it's nicer and more scalable solution.

Not the answer you're looking for? Browse other questions tagged or ask your own question.