Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

android - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...