在android日期选择器中,我需要更改完成按钮背景。
代码:
private void showDateDialog()
{
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int monthOfYear = c.get(Calendar.MONTH) + 1;
int dayOfMonth = c.get(Calendar.DAY_OF_MONTH);
String currentdate = year+"";
if(monthOfYear<10)
currentdate += "0";
currentdate += (monthOfYear);
if(dayOfMonth<10)
currentdate += "0";
currentdate += dayOfMonth;
currentDate = Integer.parseInt(currentdate);
DatePickerDialog datePickerDialog = new DatePickerDialog(SelectEvent.this, new OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int _year, int _monthOfYear,
int _dayOfMonth)
{
String date = _year+"";
if(_monthOfYear+1<10)
date += "0";
date += (_monthOfYear+1);
if(_dayOfMonth<10)
date += "0";
date += _dayOfMonth;
selectedDate = Integer.parseInt(date);
DOB = date;
if(selectedDate >= currentDate)
eventdate.setText(_dayOfMonth+"/"+(_monthOfYear+1)+"/"+_year);
else
{
eventdate.setText("");
showDialog("Please Select Event Date");
//Toast.makeText(context, "Please Select Event Date", Toast.LENGTH_SHORT).show();
}
}
}, year, monthOfYear-1, dayOfMonth);
datePickerDialog.setButton(DatePickerDialog.BUTTON_POSITIVE, "DONE", datePickerDialog);
datePickerDialog.show();
}
如果我使用此代码,我只获得默认的datepicker,只需将Done更改为DONE。 但我希望日期选择器为https://drive.google.com/file/d/0B2NGqFM-F0bNWGl2VG93OUJpaWM/edit?usp=sharing
请给出一些想法和建议如何在android中更改颜色。在这个网站我搜索但我没有。
感谢和安培;问候 香卡
答案 0 :(得分:2)
尝试以下代码。它从对话框中获取按钮并在其上设置自定义可绘制背景。
Button b = datePickerDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if(b != null) {
b.setBackgroundDrawable(getResources().getDrawable(R.drawable.your_custom_background_here));
}
答案 1 :(得分:1)
datePickerDialog.show();
datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setBackgroundDrawable(getResources().getDrawable(R.drawable.browse_background));
datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setTextSize(30);
datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setTypeface(typeface);
datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.white));
datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setText("DONE");
使用此工作正常。