The RIGHT way...
The following methods actually work.
if you wish - using a theme
By default a buttons color is android:colorAccent
. So, if you create a style like this...
<style name="Button.White" parent="ThemeOverlay.AppCompat">
<item name="colorAccent">@android:color/white</item>
</style>
You can use it like this...
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/Button.White"
/>
alternatively - using a tint
You can simply add android:backgroundTint
for API Level 21 and higher, or app:backgroundTint
for API Level 7 and higher.
For more information, see this blog.
The problem with the accepted answer...
If you replace the background with a color you will loose the effect of the button, and the color will be applied to the entire area of the button. It will not respect the padding, shadow, and corner radius.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…