Android – Why changing Color of Default Button makes it look RECTANGLE in Android

android

Why changing Color of Default Button makes it look RECTANGLE shape ? I do not want to use custom background images for this.
I want to do this programmatically for few conditions on which I change the colors of many small buttons on screen.
Can anyone give a solution ?

P.S. ==> It seems there is no workaround by reading this
http://groups.google.com/group/android-beginners/browse_thread/thread/e1313e2c98e9c52b

or is there any ?

Best Answer

For changing color :

Drawable d = findViewById(R.id.button_name).getBackground();
               PorterDuffColorFilter filter = new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
               d.setColorFilter(filter);

For removing color :

Drawable d = findViewById(R.id.button_name).getBackground();
               findViewById(R.id.button_name).invalidateDrawable(d);
               d.clearColorFilter();
Related Topic