Reputation: 384
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?
Upvotes: 8
Views: 13986
Reputation: 205
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
Upvotes: 10
Reputation: 378
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" />
Upvotes: 12