问题
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:
But I want it to look like this:
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>
andnew DatePickerDialog(getActivity(),R.style.datePickerTheme, this, year, month, day);
But the Result still is the same.
回答1:
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>
回答2:
Try like this:
style="@android:style/Widget.DatePicker"
回答3:
DatePickerDialog dateDialog = new DatePickerDialog(getActivity(),
android.R.style.Theme_Holo_Light_Dialog,
ondateSet, year, month, day);
dateDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
This is for showing white color light background Date picker Fragment.
来源:https://stackoverflow.com/questions/20835126/datepicker-with-different-style-than-activity