我有这个类java:
public class DatePickerFragment extends DialogFragment {
private Calendar date;
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
DatePicker datePicker = new DatePicker(getActivity());
date = Calendar.getInstance();
return new AlertDialog.Builder(getActivity())
.setView(datePicker)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
date.set(Calendar.YEAR, datePicker.getYear());
date.set(Calendar.MONDAY, datePicker.getMonth());
date.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
((SigninActivity)getActivity()).doPositiveClick(date);
}
}
)
.setNegativeButton("Back", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dismiss();
}
})
.create()
;
}
我想更改两个按钮“ok”和“back”的颜色。颜色是themes.xml文件中的颜色,colorPrimary,但我不知道在哪里更改此设置。
我不想更改colorPrimary,因为我只需要自定义这两个按钮。
下面是我调用datepicker来设置日期的地方:
data.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new DatePickerFragment().show(getSupportFragmentManager(), DatePickerFragment.TAG);
}
});
1条答案
按热度按时间clj7thdc1#
您可以通过在onStart()中执行以下操作来更改按钮颜色: