F. Dev F. Dev - 1 month ago 17
Android Question

Android styles doesn't allow colors

I'm new on android development .
I'm making a program and I want to change the button style , and I can do that.

here the picture about what is the button style recommend :
enter image description here

as you see it is smooth and pretty ! But when I want to change the color of the button ( with a style ) I got problem ! :
enter image description here

how can I change the style ( Button color ) and keep the button smooth and good-looking ?

Answer

Use style as theme :

 <Button
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:textColor="@android:color/white"
        android:theme="@style/blackButton"
    />

And add this style in your styles.xml

<style name="blackButton" parent="Widget.AppCompat.Button.Colored">
        <item name="colorButtonNormal">@android:color/black</item>
        <item name="colorControlHighlight">@color/colorAccent</item>
    </style>