I want to change the theme of my app with the preference of the user.
I've searched for it already but all tutorials and answers we're about changing the theme statically (e.g setTheme(R.style.Light)).
But i want the theme to be applied dynamically (eg. User chooses Theme "Dark" in the Settings -> Theme "Dark" is applied in the activity).
I'm sorry that i haven't posted some code, but i haven't achieved any good solution for now, i will post some code when i get some.
Can anybody post me some code or thoughts about how to achieve this?
I'm sorry for this elementary question, but this really freaks me out.
Thank you.
Related
I would like to do a small upgrade of my application and I would like the theme to change to dark mode after pressing SwitchPreference. I need a detailed guide or someone to explain to me exactly how to do it. If I am just learning to do something in SettingsFragment but it does not come easily to me, please help. If you do not understand the question, please write in the comments, I will try to explain everything so that the help is the best
I don't think this is the easiest way but you can give it a shot.
What you will do is to save a shared preference I will call it theme. And set it to light or dark based on user preference.
Then in homepage on create method call the shared preference and set your app theme based on what your user have set already.
I don't know if you get the idea but this is best I can explain..
At the moment im using:
android:theme="#android:style/Theme.Black.NoTitleBar"
Which I'm growing a bit bored of, Is there a link you can direct me to that shows me examples of all the inbuilt themes and their names?
I read on another post that there is quite a few so it would be best if there was a website/other source that could show me some previews :)
Thanks for the help!
Your IDE (I know Android Studio does), should show you them.
Otherwise, here they are in raw xml form. https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml
More information on Android Dev docs: http://developer.android.com/guide/topics/ui/themes.html
You can see all the theme names in the manifest.xml. For this see the following snapshot:
Android Studio has a Theme Editor which provides preview function.
User can find all built-in themes inside.
2 ways to open it:
Open a styles XML file, for instance res/values/styles.xml. Then click Open editor near the top-right of file-editing window.
in top menu bar Tools-Android-Theme Editor.
I'm pretty noobish with it all but basically I think there are only two themes. Day/Night and Light. You can select individual parts and change them but as far as I can tell there are only two themes.
As I had a comment that said this doesn't answer the question I will add that you can use Theme.AppCompat.DayNight or Theme.AppCompat.Light in the AndroidManifest.xml or in styles.xml and edit any individual attribute but there are about a million attributes and god only knows what they all do. In my opinion it's a massive oversite by android.
So I am still working on my messaging app, and I have successfully implemented a few popups on my own, but then they don't turn out exactly as I want...
The theme is supposed to be strictly black text on white background, zero transparency (Theme.Light.NoTitleBar). While I have no problems whatsoever in the activity itself, my trouble is with the popups, whose theme does not seem to match as I expected. Can anybody tell me how to fix these?
It looks like after much trial and error, I only had to force the views to use specific styles/themes.
For the popup menu (PopupWindow):
menu.setBackgroundDrawable(getResources().getDrawable(
android.R.color.background_light));
For the dialog (DialogFragment), it's...:
setStyle(android.R.style.Widget_ListView, android.R.style.Theme_NoTitleBar);
...Or it just corrected itself.
I am trying to apply my custom theme in the preference screen.
I got some hint from here(there are some Japanese but you can read the codes), but I don't know how to do it in ringtonepreference.
I got stuck in changing icons of ringtonepreference. I found they are #drawable/btn_circle
and #drawable/ic_btn_round_more, but couldn't find where can I override my images in theme.
Is there any way to do it? I think there should be some way with custom theme...
Would be grateful for any advice!
i want to add themes to my android application. In the application, user will have options to changes theme of the application. Just like OIShopping List appplication. Please help how do i implement this kind of structure to my application.
Any help, tutorials, guidance are highly appreciated.
thanks..
You can use the method
setTheme() within an onClickListener, and inbetween the parenthesis put the theme.