gpt4 book ai didi

Android 6.0 DatePickerDialog 主题

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:34:12 25 4
gpt4 key购买 nike

似乎任何使用 Marshmallow (Android 6.0) 的人都无法在我的应用程序中使用 DatePicketDialog。我遇到了某种主题问题。我使用一个 DialogFragment,其中包含一个 DatePicketDialog 供用户选择生日。以下是使用 Android 5.x 和 6.x 的 DialogFragment 的截图。

Android 5.x Android 6.x

我试图在 DatePickerDialog 构造函数中添加主题,但这使 DialogFragment 全屏显示,我不希望这样。有谁知道如何让 DatePickerDialog 看起来像 Marshmallow 之前的样子?

更新 1

这是我创建 DialogFragment 的代码:

DialogFragment ageFragment = new DatePickerDialogFragment();
ageFragment.show(getFragmentManager(), "datePicker");

这是 DatePickerDialogFragment 中的 onCreateDialog:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker if no filters are set
Calendar cal = Calendar.getInstance();
// Set the date 18 years previous, since only 18 and older are allowed on the app
cal.add(Calendar.YEAR, -18);
int year, month, day;
if (iDialogListener.getYear() == -1 || iDialogListener.getMonth() == -1
|| iDialogListener.getDay() == -1) {
Calendar defaultCal = Calendar.getInstance();
// 40 is the default age to show
defaultCal.add(Calendar.YEAR, -40);
year = defaultCal.get(Calendar.YEAR);
month = defaultCal.get(Calendar.MONTH);
day = defaultCal.get(Calendar.DAY_OF_MONTH);
} else {
year = iDialogListener.getYear();
month = iDialogListener.getMonth();
day = iDialogListener.getDay();
}

DatePickerDialog datepicker = new DatePickerDialog(getActivity(), this, year, month, day);
datepicker.getDatePicker().setMaxDate(cal.getTimeInMillis());
Calendar minDate = Calendar.getInstance();
minDate.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR) - 100);
datepicker.getDatePicker().setMinDate(minDate.getTimeInMillis());

// Create a new instance of DatePickerDialog and return it
return datepicker;
}

在 themes.xml 中,唯一涉及 Dialogs 的行是

<item name="android:alertDialogTheme">@style/CustomDialogTheme</item>

但如果我的想法是正确的,那不会触及 DialogFragment 是吗?

更新 2

这是CustomDialogTheme:

<style name="CustomDialogTheme" parent="@android:style/Theme.Holo.Light.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
</style>

最佳答案

You create theme in styles.xml but didn't refer it to DatePickerDialog like

DatePickerDialog dlg = new DatePickerDialog(getActivity(),
R.style.datepickerCustom,this,year,month,day);

并创建一个名为 values-v21 的文件夹,并向其中添加 style.xml 的副本。并粘贴

<style name="datepickerCustom" parent="@android:style/Theme.DeviceDefault.Light.Dialog">
<item name="android:colorAccent">@color/orange_theme</item>
<item name="android:windowBackground">@android:color/darker_gray</item>
<!--<item name="android:windowContentOverlay">@null</item>-->
<!--<item name="android:textColorPrimary">@color/white</item>-->
<!--<item name="android:textColorSecondary">@color/white</item>-->
</style>

关于Android 6.0 DatePickerDialog 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33767433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com