Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android DatePickerDialog accent color (in v21+)

I'm using the support library 21 for my app. My theme is also defined in values-v21, but the DatePickerDialog doesn't use the accent color for the background and text color.

What can I do to change this color to the accent color?

My current themes.xml are

values/themes.xml

<style name="AppTheme" parent="AppTheme.Base" />

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionModeOverlay">true</item>

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

values-v21/themes.xml

<style name="AppTheme" parent="AppTheme.Base">
    <item name="android:colorPrimary">@color/colorPrimary</item>
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:colorAccent">@color/colorAccent</item>

    <item name="android:alertDialogTheme">@style/AppTheme.AlertDialog</item>
</style>

<style name="AppTheme.AlertDialog" parent="android:Theme.Material.Light.Dialog.Alert">
    <item name="android:colorPrimary">@color/colorPrimary</item>
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:colorAccent">@color/colorAccent</item>
</style>
like image 543
mars3142 Avatar asked Dec 05 '14 15:12

mars3142


1 Answers

Your dialog theme needs to extend Theme.AppCompat.Light.Dialog instead of Theme.Material.Light.Dialog.Alert. Here's an example:

<!-- Base Theme Styles -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

    <!-- my theme stuff -->
    ...

    <!-- dialog theme stuff -->
    <item name="android:dialogTheme">@style/AppTheme.DialogTheme</item>

</style>

<!-- Styles for pop-up dialogs -->
<style name="AppTheme.DialogTheme" parent="Theme.AppCompat.Light.Dialog">

    <item name="android:colorPrimary">@color/primaryColor</item>
    <item name="android:colorPrimaryDark">@color/primaryColorDark</item>
    <item name="android:colorAccent">@color/accentColor</item>

</style>
like image 58
Andrew Avatar answered Nov 15 '22 21:11

Andrew