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.
Related
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
Its not so long since I started to program in Android Studio. I was wondering why everything that I'm adding (like button, the actionBar...) has already a Lilac predefined color and how I can change this color. When I tried to change the color of the button in xml of my activity nothing happened.
android:background="#color/teal_200"
Can you help me please to know where I can change this default color and why the
android:background="#color/teal_200"
didn't worked?
Thank you!
These elements will likely be in an activity and that activity will have a theme, which you can check by looking at the android:theme of the activity (or the application, if the activity doesn't have one) in AndroidManifest.xml.
If you've started a new project from a template, this theme will likely be in res/values/themes.xml and it will define colours that will be used wherever that theme is applied.
Different elements take different colours from the theme and you need to check the documentation for each one to understand where their colours come from and how to change them.
For example, if you're using a contained MaterialButton, its documentation is here. There you can see that it takes its background colour from the colorPrimary of the theme by default and this can be overridden by setting the app:backgroundTint of the button. Therefore, if you wanted to change the colour of all the contained buttons in activities that use that theme, you'd need to change the colorPrimary of the theme. You could also change the colour of individual buttons by setting the app:backgroundTint of each button.
Note that several UI elements also use the colours set in the theme (like colorPrimary) and they'll change if you change those values. There's more info about what the colours in the theme are used for here, here and here and more general info about themes and styles here.
please change in colors.xml in your resource file
Open values -> colors.xml and add the color you want and set it in the layout XML file
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.