Singed
Singed

Reputation: 1113

Define default button Style for a theme

I'm trying to apply default button style for theme. The theme is correctly applied to my app in the Manifest. In my gradle dependencies, I have design support library version 22.2.1 (this library has appcompat library as a dependency, so I guess I'm using the same version of the appcompat support library?)

When I define my theme like this, the button styles are applied correctly in the layout preview, but now when I launch the app:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:buttonStyle">@style/Widget.Button</item>
</style>

When I define my theme like this, the button styles are applied correctly when app is launched, but not in the layout preview:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="buttonStyle">@style/Widget.Button</item>
    </style>

Problem: I want this to work in both layout preview and in runtime, is there a way to achieve this?

Is this a bad solution?

   <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
     <item name="buttonStyle">@style/Widget.Button</item>
     <item name="android:buttonStyle">@style/Widget.Button</item>
        </style>

Upvotes: 1

Views: 1680

Answers (1)

ingyesid
ingyesid

Reputation: 2884

Colored Button Style With AppCompat +22 in your styles.xml

<style name="Button.Tinted" parent="Widget.AppCompat.Button">
        <item name="colorButtonNormal">YOUR_TINT_COLOR</item>
        <item name="colorControlHighlight">@color/colorAccent</item>
        <item name="android:textColor">@android:color/white</item>
</style>

in your layout.xml

<Button
        android:id="@+id/but_next"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/but_continue"
        android:theme="@style/Button.Tinted" />

important use android:theme

https://gist.github.com/ingyesid/e513f47b573607205195

Upvotes: 0

Related Questions