-1

我有这个日期选择器对话框片段的代码

public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {

@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
return new DatePickerDialog(getActivity(), this, year, month, day);
}

public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
}
}

我像这样运行它:

DialogFragment newFragment = new DatePickerFragment();
                newFragment.show(getFragmentManager(), "datePicker");

这给了我这个对话框:

在此处输入图像描述

当我希望它给我这样的东西时:

在此处输入图像描述

如何以编程方式或通过 xml 更改主题?我更喜欢xml,所以代码更少,但我不介意......

谢谢

4

1 回答 1

7

Datepicker构造函数接受 Theme 作为参数:

DatePickerDialog(Context context, int theme, this, int year, int monthOfYear, int dayOfMonth);

所以主题参数是:

android.R.style.Theme_Holo_Light_Dialog_NoActionBar

编辑:我认为您正在寻找的是:

 public static final int Theme_Holo_Dialog_NoActionBar = 16973937;
于 2013-10-11T07:35:05.740 回答