I am trying to set the background color of a button in my app and I am unable to achieve the result that I want...
The color that I am trying to set is holo_gr
If you don't mind hardcoding it you can do this ~> android:background="#eeeeee" and drop any hex color # you wish.
Looks like this....
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1"
android:text="@string/ClickMe"
android:background="#fff"/>
In order to keep the style, use:
int color = Color.parseColor("#99cc00");
button.getBackground().mutate().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC));
With version 1.2.0-alpha06 of material design library, now we can use android:background="..."
on MaterialButton
components:
<com.google.android.material.button.MaterialButton
android:background="#fff"
...
/>
Why not just use setBackgroundColor(getResources().getColor(R.color.holo_light_green))
?
Edit: If you want to have something which looks more like an Android button you are going to want to create a gradient and set it as the background. For an example of this, you can check out this question.