Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does changing background color in android destroy the widget's appearance?

I've noticed that changing the background color of an android widget (ex. Button or TextView) by program:

myButton.setBackgroundColor(Color.BLUE);

makes it to loose its 3D shape, border, and shadows effects, and then appears like a ugly flat square. What am I missing?

Sorry for the very naive question but I couldn't get it right although tried for a time.

like image 512
cibercitizen1 Avatar asked May 23 '10 18:05

cibercitizen1


2 Answers

Rounded corners, shadow effects, etc are often accomplished in Android by using images. See this developer documentation for an explanation of how that works.

A widget can have either an image background, or a solid color background. So, by setting the background color you are override the background image. If you want to change the color without losing everything else, you need to edit the image files.

like image 83
Cheryl Simon Avatar answered Sep 19 '22 18:09

Cheryl Simon


See:

  • How to set background color of a View
  • Is it possible to have a Button with a background image with text on top?
  • How to gradient fill a button's background?
  • Problem with EditText background (android)
like image 40
CommonsWare Avatar answered Sep 20 '22 18:09

CommonsWare