Android button background color

后端 未结 10 1894
轮回少年
轮回少年 2020-12-08 00:25

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

相关标签:
10条回答
  • 2020-12-08 00:47

    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"/>
    
    0 讨论(0)
  • 2020-12-08 00:49

    In order to keep the style, use:

    int color = Color.parseColor("#99cc00");
    button.getBackground().mutate().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC));
    
    0 讨论(0)
  • 2020-12-08 00:55

    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"
        ...
    />
    
    0 讨论(0)
  • 2020-12-08 00:57

    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.

    0 讨论(0)
提交回复
热议问题