Android Question How to add image on colordrawable button?

capisx

Member
Licensed User
Longtime User
Hi everyone,

I want to make a round button with changeable background color that has an image in the middle of it, i can set and change the color with statelist colordrawable but i can't add image on it.

I also try to add imageview on top of the button but the button always on top of it even though i set BringToFront to the imageview it will still at the back of the button (the button and the imageview is in the same panel).

Could somebody can help me to solve this?

Thanks.
 

Mark Read

Well-Known Member
Licensed User
Longtime User
There is probably a better way but I used a small panel with an imageview on top. The panel is slightly bigger than the image and I change the color of the panel to show the image has been clicked.
 
Upvote 0

capisx

Member
Licensed User
Longtime User
There is probably a better way but I used a small panel with an imageview on top. The panel is slightly bigger than the image and I change the color of the panel to show the image has been clicked.

Thanks Mark for the solution, but i like the default button appearance and effect, also i need the up & down event that the button has.

You can add the image with the designer by using a BitmapDrawable. A simple solution is to include the background color in the image.

Thanks Erel, the reason i want to make this button is to be able to change the background color in the app (like theme) and i don't want to create many same images with different background color for the same button to minimize the apk size.

For now, i use 2 stacking panel to achieve it, one panel contain the colordrawable button and the other contain the imageview.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…