我想改變timepicker對話框片段的默認顏色。 現在我不知道我應該做什麼。如何更改默認顏色方案timepicker對話框片段?
這是我設法我的主題設置爲(withouth的的動作條):
但這是對話框我得到:
這是我的XML樣式文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/color_accent</item>
<item name="colorPrimaryDark">@color/color_secondary</item>
<item name="colorAccent">@color/color_accent</item>
<item name="android:statusBarColor">@color/color_primary</item>
</style>
</resources>
我的色彩文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="flat_text">#f14268</color>
<color name="background_flatbtn">#fff</color>
<color name="color_accent">#f14268</color>
<color name="color_primary">#d83b5d</color>
<color name="color_secondary">#d83b5d</color>
</resources>
mytimepicker片段:
public class DialogHandler extends DialogFragment
implements TimePickerDialog.OnTimeSetListener {
Context context;
public DialogHandler(Context context){
this.context=context;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
TimePickerDialog dialog= new TimePickerDialog(new ContextThemeWrapper(getActivity(),R.style.AppTheme), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
// Create a new instance of TimePickerDialog and return it
return dialog;
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Do something with the time chosen by the user
Toast.makeText(context, "your time is selected",Toast.LENGTH_LONG).show();
}
}
我對話的呼叫:
DialogHandler newFragment = new DialogHandler(getApplicationContext());
newFragment.show(getSupportFragmentManager() , "time_Picker");
請幫助我。 在此先感謝:)
可能重複【如何改變的DatePicker和TimePicker對話框中Android的默認顏色?](http://stackoverflow.com/questions/11077530/how-to-change-the-default-color-of-datepicker-and-timepicker-dialog-in-android) –