目前,我的datepicker对话框看起来像这样。但这是使用Theme_Holo_Light_Dialog
主题。
但是我希望通过使用AppCompat对话框样式的标题和按钮实现以下内容(根据我的理解,它是材质主题),但中心微调器仍然保持非材质样式(选择)。
答案 0 :(得分:0)
解决了这个问题!
我没有遇到设置对话框样式的问题,而是使用AlertDialog
并夸大了包含DatePicker
的布局。
<强> datepicker.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/daily_datepicker"
android:layout_centerInParent="true"
android:calendarViewShown="false"
android:datePickerMode="spinner"/>
</RelativeLayout>
和代码隐藏......
public AlertDialog.Builder displayDailyOverviewDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View dialogView = inflater.inflate(R.layout.datepicker, null);
dialog.setTitle("Set Daily Overview");
dialog.setView(dialogView);
DatePicker dp = (DatePicker) dialogView.findViewById(R.id.daily_datepicker);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 1);
dp.setMinDate(calendar.getTimeInMillis());
dp.setMaxDate(new Date().getTime());
dp.findViewById(Resources.getSystem().getIdentifier("month", "id", "android")).setVisibility(View.GONE);
dp.findViewById(Resources.getSystem().getIdentifier("year", "id", "android")).setVisibility(View.GONE);
dialog.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.create();
return dialog;
}