日期选择不同的款式比活动 [英] datepicker with different style than activity

查看:172
本文介绍了日期选择不同的款式比活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义样式的活动,我想我有一个自定义标题栏的活动,所以我创建了以下方式:

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>

在清单中我使用:

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

在我使用的活动:

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

到目前为止,这是好的,工作得很好,我有活动与我的自定义标题栏。
现在我想用datePickerDialog。问题是,对话框看起来老:

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:

我也有这个款式:

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

所以,我用它来创建DatePickerDialog是这样的:

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.

只是一个测试,我创建的默认样式第二个应用程序,只有一个按钮,打开日期选择器,所以日期选择器 貌似我想要的。这两个应用程序具有安卓的minSdkVersion =8

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?

编辑:

我改变了安卓的minSdkVersion =11

 &LT;样式名称=datePickerTheme父=@安卓风格/ Widget.Holo.DatePicker&GT;&LT; /风格&GT;
   和
新DatePickerDialog(getActivity(),R.style.datePickerTheme,这,年,月,日);

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);

但结果仍是相同的。

推荐答案

我知道这是有点晚,但我走进这个话题,而我正在寻找别的东西约DatePickers。

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>

这将覆盖使用的是母的主题和结果的不同期待的DatePicker。

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.

我的主题例:

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

这篇关于日期选择不同的款式比活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆