要更改Android时间选择器中选定AM/PM的颜色,可以通过以下步骤实现:
在代码中,我们可以看到在该自定义layout中,添加了amPmTextColor属性来更改选中的AM/PM的颜色,其他的属性也可以根据需要进行修改。
private void showTimePickerDialog() {
LayoutInflater inflater = LayoutInflater.from(getContext());
View view = inflater.inflate(R.layout.custom_time_picker, null);
TimePicker timePicker = view.findViewById(R.id.timePicker);
// Set default time
timePicker.setIs24HourView(false);
timePicker.setCurrentHour(12);
timePicker.setCurrentMinute(0);
// Build and show time dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("Choose Time");
builder.setView(view);
builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Handle time set event
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Handle cancel event
}
});
builder.show();
}
通过这些步骤,我们可以自定义Android时间选择器的外观,包括选定AM/PM的颜色。