datepicker的风格与活动不同

meh*_*dok 6 android android-datepicker android-theme android-styles

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

<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>
Run Code Online (Sandbox Code Playgroud)

在清单中我使用:

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomTheme" >
Run Code Online (Sandbox Code Playgroud)

在我使用的活动中:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.setting_activity_titlebar);
Run Code Online (Sandbox Code Playgroud)

到目前为止它很好并且工作正常,我有自定义标题栏的活动.
现在我想使用datePickerDialog.问题是对话框看起来很旧:

在此输入图像描述

但我希望它看起来像这样:

在此输入图像描述

我也有这种风格:

<style name="AppBaseTheme" parent="android:Theme.Light">
Run Code Online (Sandbox Code Playgroud)

所以我用它来创建DatePickerDialog,如下所示:

new DatePickerDialog(getActivity(),R.style.AppBaseTheme, this, year, month, day);
Run Code Online (Sandbox Code Playgroud)

但主题不适用.

只是为了测试,我创建了一个默认样式的第二个应用程序,只有一个按钮来打开日期选择器,所以datepicker看起来像我想要的.两个应用都有android:minSdkVersion="8"

我认为问题出在自定义标题栏上,那么我如何才能获得所需风格的自定义标题栏和日期选择器呢?

编辑:

我改变android:minSdkVersion="11"

<style name="datePickerTheme" parent="@android:style/Widget.Holo.DatePicker"></style>

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

但结果仍然是一样的.

erk*_*ldz 13

我知道这已经很晚了,但是当我在搜索关于DatePickers的其他内容时,我走进了这个主题.

将其添加到您正在使用的自定义主题中:

<item name="android:datePickerStyle">@android:style/Widget.DatePicker</item>
Run Code Online (Sandbox Code Playgroud)

这将覆盖您正在使用的父主题,并将结果显示为不同的DatePicker.

您需要使用此自定义主题创建对话框.

我的主题示例:

<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>
Run Code Online (Sandbox Code Playgroud)


小智 7

试试这样:

style="@android:style/Widget.DatePicker"
Run Code Online (Sandbox Code Playgroud)


Ran*_*a.S 5

DatePickerDialog dateDialog = new DatePickerDialog(getActivity(),
                                                   android.R.style.Theme_Holo_Light_Dialog,
                                                   ondateSet, year, month, day);
dateDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Run Code Online (Sandbox Code Playgroud)

这是为了显示白色的浅色背景日期选择器片段。