Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize AppCompatButton color

I saw new appCompat controls are available here. And implemented it in android app, but I don't find any specific way of customizing its color.

Just like if we set accent color in style, the edit text automatically catches it. But it is not working in case of AppCompatButton.

Does anybody find something regarding this?

like image 650
Krunal Panchal Avatar asked May 05 '15 06:05

Krunal Panchal


2 Answers

See here: Coloring Buttons in Android with Material Design and AppCompat

To summarize, you can use the tintBackground attribute on the button itself or you can use colorControlNormal (or a combination).

Also, you can just use Button and it'll get converted to an AppCompatButton as long as you're using the theme and inheriting from AppCompatActivity correctly.

Examples from the linked URL

theme.xml:

<item name="colorButtonNormal">@color/button_color</item>

v21/theme.xml

<item name="android:colorButtonNormal">@color/button_color</item>

or

<Button
       android:id="@+id/add_remove_button"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:backgroundTint="@color/bg_remove_btn_default"
       android:textColor="@android:color/white"
       tools:text="Remove" />
like image 99
David Whitman Avatar answered Oct 19 '22 01:10

David Whitman


Use the SupportLib with AppCompatButton like this:

<android.support.v7.widget.AppCompatButton
       android:id="@+id/add_remove_button"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       app:backgroundTint="@color/bg_remove_btn_default"
       android:textColor="@android:color/white"
       tools:text="Remove" />

app is a mxlns: xmlns:app="http://schemas.android.com/apk/res-auto"

so the backgroundTint works also for preLollipop

like image 28
André Bäuml Avatar answered Oct 19 '22 00:10

André Bäuml