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 ?
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 .
To change the default Button style of the application we can use the android:buttonStyle attribute in the AppTheme style inside the styles. xml.
When I open a new android studio project, the default color for button is purple.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With