问题描述
我使用的是DialogFragment打开DatePickerDialog
I'm using a DialogFragment to open a DatePickerDialog
public class DatePickerFragment extends DialogFragment{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
DatePickerDialog DatePickerDialog = new DatePickerDialog(getActivity(), (ProfileCreationActivity)getActivity(), year, month, day);
return DatePickerDialog;
}
}
我得到一看日历
我想preFER一个微调的外观
I'm getting a calendar lookI would prefer that a spinner look
我试过:
datePickerDialog.getDatePicker().setCalendarViewShown(false);
和
datePickerDialog.getDatePicker().setLayoutMode(1);
这是行不通的。
请注意,我想微调找一个活动,但我会想为另一个活动日历视图。所以,我不能改变整个应用程序的风格。我需要一个自定义样式的一个活动。
Please note that I want the spinner look for one activity, but that I will want the calendar view for another activity. So I can not change the whole application style. I need a custom style for one activity.
感谢您
推荐答案
我发现在以下职位的解释(描述非常类似地雷的问题):
I have found a the explanation in the following post (which describes a problem very similar to mine) :
Android材料设计内嵌日期选择问题
在事实上setCalendarViewShown(假)和setSpinnersShown(真)显然不是最新版本工作了。
In fact the setCalendarViewShown(false) and setSpinnersShown(true) are apparently not working anymore in latest versions.
我们必须使用显式XML属性像这样的的android:datePickerMode =微调
We have to use an explicit XML attribute like this one android:datePickerMode="spinner".
问题是,我使用的是DialogFragment没有任何XML布局(只是一个日期选择器对话框)。所以,我不能设置任何XML属性。
The problem is that I'm using a DialogFragment without any XML layout (just a date picker dialog). So I cannot set any XML attribute.
解决方案是使用请求属性来创建一个XML布局文件专门定制对话框。
The solution is to create a dedicated custom dialog with an XML layout file using the requested attribute.
这篇关于不可能让我DatePickerDialog使用微调编程风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!