当我尝试永久设置 DatePickerDialog 标题时遇到问题。
DatePickerFragment.java
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
DatePickerDialog dpd = new DatePickerDialog(getActivity(), this, year, month, day);
dpd.setTitle("set date");
return dpd;
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
}
}
MainActivity.java
public class MainActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "datePicker");
}
});
}
}
当我单击按钮 DatePickerDialog 显示并且对话框标题是“设置日期”但是当我更改日期时,标题包含选定日期而不是“设置日期”。如何永久设置此对话框标题?
在 API 8-10 上测试。
提前谢谢你,对不起我的英语。帕特里克