我想以 EEEE d, MMMM 格式自定义此显示日、日期和月份格式。
提前致谢。
最佳答案
这是完全合乎逻辑的。你可以试试这个
public static class EndDatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
public AdvancedSearchFragment instant;
public int dd = 0, mm, yyyy;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
if (dd == 0) {
final Calendar c = Calendar.getInstance();
yyyy = c.get(Calendar.YEAR);
mm = c.get(Calendar.MONTH);
dd = c.get(Calendar.DAY_OF_MONTH);
}
DatePickerDialog dpd = new DatePickerDialog(getActivity(), this, yyyy, mm, dd);
// Added all possible null conditions
((TextView)((LinearLayout)((LinearLayout)((LinearLayout)((DatePicker)dpd.getDatePicker()).getChildAt(0)).getChildAt(0)).getChildAt(0)).getChildAt(1)).setText("My Date");
return dpd;
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
instant.doSetEndTime(year, month + 1, day);
}
}
下面这一行将设置 Fri, Oct 13 的值
((TextView)((LinearLayout)((LinearLayout)((LinearLayout)((DatePicker)dpd.getDatePicker()).getChildAt(0)).getChildAt(0)).getChildAt(0)).getChildAt(1)).setText("My Date");
如果您想更改 2017 年的格式,请使用以下内容
((TextView)((LinearLayout)((LinearLayout)((LinearLayout)((DatePicker)dpd.getDatePicker()).getChildAt(0)).getChildAt(0)).getChildAt(0)).getChildAt(0)).setText("My Year");
因此,您可以使用日期格式代替我的日期,并根据需要设置日期。
希望对您有所帮助!
关于android - 更改Android DatePickerDialog中日期、星期、月份的显示格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46728267/