When I remove the activity theme from its directive ([activity(Theme =)]) and set it in activity's OnCreate overrided method before base.OnCreate I expect the result be same but it does not. When I run app, first I see Android default theme then SetTheme change theme. As far as I know the OnCreate implement before an Activity is created!
Save theme state on sharedPreferences, then load it inside onCreate(). When user click change theme, you need to reload activity, by starting it again.
Related
I am setting the night mode in onCreate of an activity. So every single activity in the app turns to night mode and all the previous activities gets recreated. But I need only that particular activity to be in night mode and all other activities to be in light mode. How to achieve this ? Below line of code I am using in oncreate of an activity to set to night mode.
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
Try This to Set Modes Only for Single Activity
Light Mode
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
Dark Mode
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
System Default
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
sadly you don't have option for switching only one Activity into dark mode leaving all others in light. setDefaultNightMode is one and only method and it is working for whole Application and all Activities running in it.
you have to make two separated styles/themes for this one Activity and switch its theme programmatically (here you find out how) or if this one Activity is always dark then set its theme straight inside manifest
you can change the theme of the activity in the manifest file
I want change hole application theme and i can do it and handle this by saving in sharedPreference and set theme in my BaseActivity.
Changing theme is in separate activity, but when i go back to previous activity it has not updated theme.but if i close the application and reopen or move to unopened activity, theme changed.
I tried to set theme in onResume but nothing changed.
Theme can only be set before setContentView() is called in your Activity. You can try something like calling recreate() after updating your theme, but I would advise against that.
Here are some popular theming libraries that handle these things for you:
Aesthetic
Colorful
Magica Sakura
I have an activity in Android. Specifically, I am using Xamarin.Android, formerly monodroid. I have an activity. When it is running on a phone (small screen device), we want the activity to be full screen. When it runs on a tablet, we want the activity to have a "border" around similar to a dialog. I do a programmatic check to get the screen dimensions and then determine if we are on a tablet or phone. If we are on a phone, I call an activity's SetTheme method and pass in a dialog theme. I have tried several dialog themes with no difference. My menu items do not show. I track this down and my overridden OnCreateOptionsMenu method is not called. I know because I set a breakpoint in the first line of my activty's OnCreateOptionsMenu method and the breakpoint is not hit.
The code that I am using to set the theme is:
this.SetTheme (Android.Resource.Style.ThemeDialog);
I've also tried this from the Activty's theme attributes, but I am getting the same result.
I'm looking for any ideas, thoughts, whatever.
Thanks for your time.
Wally
By default the dialog theme does not have an actionbar. No reason to create menu items without it (on newer android versions).
Call RequestWindowFeature (WindowFeatures.ActionBar); in onCreate to get an actionbar in a dialog themed activity. Then OnCreateOptionsMenu will be called
In my application i am using a splash screen for the application start up with the theme #android:style/Theme.Black.NoTitleBar.Fullscreen.
After 2 seconds the app goes on to the main activity which uses this theme: #style/Theme.Sherlock.Light.DarkActionBar.
One is in full screen, the other one is not. The transition between both is not smooth and it takes a while (~1 seconds) for the main activity to adjust to the status bar. Is there some trick to avoid this?
As far as I know, there is no api level solution for this. I suggest Using TransitionDrawable for example changing background color and/or PropertyAimation for changing view's properties like background color or text color. Then you can call setTheme() function of activity to apply your new theme. be careful that setTheme() must be called in onCreate() function before setContentView.
I have an application with a MainActivity and few other activites. From the MainActivity I start a preference screen, where I set theme for my application.
MainActivity-> Settings->Choose Theme
Currently how it works:
I restart the application, start my Main activity and theme is applied to all the activites.
How I want it to work:
I want to restart the application and go back to the same screen where I set my Theme and not my MainActivity.
Can anyone please suggest me some ways in which I can do it?
Thank you in advance
EDIT:
How I want it to work:
Restart the application -> Go back to the "Choose Theme" Screen (Where it is set) .
Then when I press back button -> Settings screen -> and when pressed back again to my MainActivity.
I don't know if this is the best way, but you can save in SharedPreferences the Last screen you were on (or if it's just for this case, a boolean to know if you're coming from a restart)
and each time when the application start on onCreate() of MainActivity check the key in SharedPreferences and go to your Themes activity accordingly