I have a android custom view that start a custom action view when long clicked, as such, it require the theme of the activity to have the style "windowActionModeOverlay" set to true. I don't want to define a custom theme. I want to use whatever theme the user provided for the activity, and set the style to true at runtime using code myself.
Is this possible ?
Please note any suggestion by changing style xml file is not what I am looking for, unless it allow user to use whatever theme they choose for their activity.
Thanks
There are tons of solution for changing the style of a single view. There are tons of solution for changing theme at runtime, but I only want to change a single style of a theme, and so far, I can not find a solution myself or online
Related
I'm building a material design playground that can switch between the available pre-defined themes that can apply the color, typography and shapes to all the material design components throughout the app.
Right now, the user can choose available themes from the PreferenceScreen:
I got a NEW requirement that should allow the user to enter a value (eg. set color of colorPrimary). From the input, I would like to modify the Theme directly so that it could apply the change in the app.
How can I do this? I'm thinking of giving an option to the user something like below:
Here's a link to my sample material design playground app:
https://github.com/ciscosoriano/material-design-dynamic-theming
Seems like you need something like this android-how-to-change-application-theme-programmatically
link: android-how-to-change-application-theme-programmatically
This should be easy and there are lot of tutorials out there, don't forget to checkout
Basically what you need to do is:
apply statically defined theme(in res/values) as usual before activity is launched.
Now get the user input when activity is launched
Then get the current theme attributes using appropriate api and recolourize the ui controls dynamically in the program.
restart activity with the updated theme.
Some more link: Set theme color dynamically
You should be comfortable handling the activity lifecycle to view the updated theme when set.
I have a requirement to display a theme that comes from a webservice (return the color etc). What I want to know is can I create a style programmatically? I have my code setup to incorporate theme and I have 2 themes defined in xml which work perfectly fine. And now I want to add a third theme which is not locally in an xml. Is this even possible?
The other approach to achieve this is to create custom classes for views and apply the style according to the theme. Which is I don't want to do, as it is very tedious and error prone.
Any other suggestions are welcomed as well.
Is there a way to replicate the color changing ability provided by QKSMS .
It allows a user to select a color and then changes the app color and everything to that color.This is all done dynamically the moment the user chooses a specific color.
You can try this cool online tool: http://android-holo-colors.com
This enables you to create many themes for app widgets with your preferred color. You can then change your app theme by saving values for your theme in SharesPreferences or something similar and apply them in onCreate of each activity you have in your app. You can also create the themes easily in styles.xml. For each view, it has its own style with its own attributes so you will need to learn how to edit the theme of each view you want by searching...
Hope that helps.
Some Examples:
ActionBar:
https://developer.android.com/training/basics/actionbar/styling.html
Buttons:
https://www.androidcookbook.com/Recipe.seam?recipeId=3307
SeekBar:
Android - styling seek bar
Switch:
How can I style an Android Switch?
And a lot more... You will have to search for what you want.
My experience up until now when dealing with styles has been to create a style.xml file and create the properties I want for the style. If I want my style to be based on an existing style, I use the parent attribute. I then specify the style inside of my layout file on the controls that I want to apply the style to.
Where I am at a loss is when I want to use system styles and only update certain properties. I am wondering whether I can leave the layout files alone and not bother applying any styles to the controls. Instead, I would somehow update the property of the system style and that would update everywhere in my app where that style is already being used by default.
More specifically, I want to change the background color of the Actionbar but haven't found a way of doing it other than the way I described above.
You're probably looking for themes, which are collections of styles, applied either globally throughout the application, or for each Activity in particular. Start with this document and investigate further.
Does anyone know how to apply the Light theme to single controls? While using the standard Holo-Dark-theme, I want to do something like this:
<CheckBox style="#android:style/Widget.Holo.CompoundButton.CheckBox"></CheckBox>
But for some reason that doesn't work.
You can not apply a theme to a single control. Themes can only be applied to activites. You can apply a style to single control but this does not help in this case as you already noticed because the Widget.Holo.CompoundButton.CheckBox style does not add anything to the parent style Widget.CompoundButton.CheckBox.
Instead the whole styling takes place in the listChoiceIndicatorSingle selector of the current theme.
So your only choice is to replace this selector by your own as described e.g. here: Setting Theme.Holo.Light changes everything except checkboxes in list
Read up on this page about Styles and Themes in Android. It goes over how to define which theme to use for a specific Activity or a whole Application. You will also see how to customize themes and styles, and how to mix and match them.