I'm using Material 3 ButtonToggleGroup, I want to have a different background when a button is selected. However, If I don't add any attributes to my style applied to MaterialButton, I get the background set to colorPrimary when a button is selected but when it's not it's transparent.
When I add a backgroundTint attribute, it always has the same background color, no matter if the button is selected.
Related
I want to highlight a CheckBox by setting a custom color to its background and then fade that color into whatever was the original background color.
The issue is I don't know how to obtain the "colorTo" for ValueAnimator. Does CheckBox even have something that could be called a background? Or is it merely a text next to a tick-box?
The Checkbox is created at runtime, i.e. by calling its constructor. And I only set its text and an onClick handler, I do not set its bg.
Yes it has a background. Since you creating it at run time the background is not set so it is Transparent (Unless defined otherwise in Style).
For highlighting Button momentarily you can set a desired highlight color and animate the color from Highlighted color to Background color or simply animate it to Transparent color -> "#00000000"
P.S: You probably wont need this but to get background color of a view you can do this:
int color;
Drawable background = view.getBackground().mutate();
if (background instanceof ColorDrawable) {
color = ((ColorDrawable)view.getBackground()).getColor();
}
The mutate() will clone your background so if you used this background in multiple places, with the change of background the other backgrounds won't change.
If I change the Alpha setting on a Button widget to make it translucent, then add a background image to the Button, will the image also be translucent?
Yes. Changing the background property will override any of the styling you have applied to the button and use only that. So if you use a Material-style button that has custom colors, then apply a background property, the "button" will disappear and be only a perfect rectangle of whatever color (including alpha) that you set, with text/drawables on top.
I have a multichoice ListView whose items have a light (transparent) background by default and a dark one while selected. Therefore, I would like to have the TextViews in the items change their color accordingly, i.e. black by default and white while selected.
Obviously, I can manually define a selector that does this, but is there some predefined color or style in the Android SDK that I could use out of the box?
Just for illustration, the navigation drawer in Gmail does this:
I want to change the background color of spinner and customize spinner. When I used this code in xml android:background="#000000" the color changed but the arrow on the spinner disappears. How can I cuztomize spinner and change the background color without disappearing the arrow?
The arrow is black (or close to it) by default, so it won't show up on a black background. You can change the arrow with the android:dropDownSelector attribute in your XML.
The "background" attribute on a spinner refers to a drawable which contains the background color and the arrow. By specifying a color for the background, there is no longer any arrow. To fix this you need to provide a new 9 patch drawable with the arrow in it.
I want to implement the below:
A spinner which would have a custom layout, its background color would be black and font would be white. But what I want is that when I select any component then my selection background and font color should reverted back to its defaults (in terms of color).
#Rao use custom Spinner and for colour state change use Color State list