Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 ?

like image 505
Pritam Avatar asked May 05 '10 04:05

Pritam


People also ask

How to change the shape of Button in android?

We can set custom shapes on our button using the xml tag <shape> . These xml files are created in the drawable folder too. shape can be used inside selectors . The shape can be set to rectangle (default), oval , ring , line .

How do I change the default button color?

To change the default Button style of the application we can use the android:buttonStyle attribute in the AppTheme style inside the styles. xml.

What is the default button color in android?

When I open a new android studio project, the default color for button is purple.


1 Answers

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();
like image 162
Pritam Avatar answered Nov 15 '22 12:11

Pritam