Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datepicker with different style than activity

I have activities with custom style, I want my activity with a custom title bar so I created below style:

<style name="costum_titlebar">
    <item name="android:background">@color/titlebar_background</item>
</style>

<style name="CustomTheme" parent="android:Theme">
    <item name="android:windowTitleSize">@dimen/titlebar_size</item>
    <item name="android:windowTitleBackgroundStyle">@style/costum_titlebar</item>
</style>

In manifest I use:

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomTheme" >

In the activity I use:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.setting_activity_titlebar);

So far it's good and works fine, I have activity with my custom title bar.
Now I want to use datePickerDialog. The problem is that dialog looks old:

enter image description here

But I want it to look like this:

enter image description here

I also have this style:

<style name="AppBaseTheme" parent="android:Theme.Light">

So I used it to create DatePickerDialog like this:

new DatePickerDialog(getActivity(),R.style.AppBaseTheme, this, year, month, day);

But the theme won't apply.

Just for a test, I create a second app with default style and just one button to open date picker, so the datepicker Looks like what I want. Both apps have android:minSdkVersion="8"

I think the problem is with custom titlebar, so how I can get my custom titlebar and datepicker with desired style?

EDIT:

I Changed android:minSdkVersion="11"
with
<style name="datePickerTheme" parent="@android:style/Widget.Holo.DatePicker"></style>
and
new DatePickerDialog(getActivity(),R.style.datePickerTheme, this, year, month, day);

But the Result still is the same.

like image 610
mehdok Avatar asked Dec 30 '13 07:12

mehdok


2 Answers

I know this is little late but I walked into this topic while I was searching something else about DatePickers.

Add this to the custom theme you are using:

<item name="android:datePickerStyle">@android:style/Widget.DatePicker</item>

This will override the parent theme you are using and result as a different looking DatePicker.

You will need to create the dialog with this custom theme.

Example of my theme:

<style name="CustomTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
    <item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
    <item name="android:actionButtonStyle">@style/MyActionBarButtonStyle</item>
    <item name="android:actionMenuTextColor">#ffffff</item>
    <item name="android:windowBackground">@drawable/bg</item>
    <item name="android:datePickerStyle">@android:style/Widget.DatePicker</item>
</style>
like image 171
erkinyldz Avatar answered Nov 08 '22 05:11

erkinyldz


Try like this:

style="@android:style/Widget.DatePicker"
like image 7
jinal Avatar answered Nov 08 '22 05:11

jinal