Give app widget button custom colour with rounded rectangle shape - android

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?

Related

How to set progressBar color in android?

So far I am just seeing an option to set background. I want to set the filled portion to one color and the unfilled portion to another color.
I think you could achieve this, setting background of progressBar to color of unfilled portion and setting progressTint to filled portion color.

How to obtain CheckBox background color

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.

Create android selector extending background ?attr/selectableItemBackground?

I want to create a button background, which is exactly the same as ?attr/selectableItemBackground but with a black stroke outline.
Is there a way to "extend" ?attr/selectableItemBackground and add a black outline or will I have to create a completely new stateList?

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.

when i set the background color of the button it's edges is disappeared

I am using default android button in my application.
But when I set its background color its edges will disappear

Categories

Resources