koa73
koa73

Reputation: 881

How to inherit style of AlertDialog buttons

I wanna make style of my buttons at fragment like AlertDialog, how can I do it Which style I should inherit or set for my buttons

My styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:spinnerItemStyle">@style/Spinner</item>
</style>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

Thanks

Upvotes: 2

Views: 1364

Answers (1)

GGDev
GGDev

Reputation: 600

Here's a quick example of how i have done this in an app. You need to set an alertDialogTheme in your AppTheme. You also can apply styles to the buttons as well. Here's an example using your code.

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:spinnerItemStyle">@style/Spinner</item>
    <item name="android:alertDialogTheme">@style/AlertDialogTheme</item>
</style>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="android:textColor">@android:color/black</item>
        <item name="android:textColorPrimary">@android:color/holo_red_dark</item>
        <item name="android:textColorSecondary">@android:color/holo_orange_light</item>
        <item name="colorAccent">@android:color/holo_purple</item>
        <item name="colorControlHighlight">@android:color/holo_purple</item>
        <item name="buttonBarNegativeButtonStyle">@style/NegativeButton</item>
        <item name="buttonBarPositiveButtonStyle">@style/PositiveButton</item>
</style>

<style name="NegativeButton"
       parent="android:Widget.DeviceDefault.Button.Borderless">
    <item name="android:textColor">@android:color/holo_green_dark</item>
</style>

<style name="PositiveButton"
       parent="android:Widget.DeviceDefault.Button.Borderless">
    <item name="android:textColor">@android:color/green</item>
</style>

Upvotes: 2

Related Questions