How to obtain CheckBox background color - android

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.

Related

Can't get different state background for MaterialButtonToggleGroup

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.

Android UI Button Alpha Property

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.

Android ListView alpha in background color only

I have a list view and now all cells have white background.
What I want is to keep the white color in listview's background and put some "alpha" value to make it semi transparent so the user can see the whole view's background.
If I put android:alpha in listview , everything gets alpha ( the content too ). I want the content of the listview to be fully visible and the background color to be semi-transparent. Is there any way to achive this?
Don't use white color as background, define a color in resources that has a transparency, you could do something like #66FFFFFF, this is a transparent white.

Android ImageButton push color

I have an ImageButton that I switch the images when pushed. The problem is that the animation tints the button blue when I push the button between my two image switches. How to I prevent that blueish tint from animating? Also, how do you do it programatically and not through the XML.
Well for most use cases, you should be using XML... but lecture aside, the blue background is part of a StateListDrawable that is set by default as your button's background. Defining and setting your own background (via setBackgroundResource(int resId) or similar) should be sufficient to "get rid" of the focused color state.

Give app widget button custom colour with rounded rectangle shape

I've got an app which creates widgets where the user can set the colour of the button's background via a colour picking dialog. However, the only way I can set the button in the remote view to have this colour is by doing this
rv.setInt(R.id.button, "setBackgroundColor", colour);
but this always makes the background a rectangle shape, replacing any previously set background drawable. What I would like to do is have the button as a rounded-corners rectangle shape which can be set to a custom colour. Is this possible, and if so how?

Categories

Resources