Ich möchte die Standardfarbe des Datums-/Zeitauswahldialogfelds in Android ändern, damit es dem Design meiner App entspricht. Ich habe bei Google nach der Lösung gesucht, konnte aber keine Lösung finden.
Was ich tat, war die Schaffung eines neuen Stils:
<style name="datepicker" parent="@Android:style/Widget.DeviceDefault.DatePicker">
<!---TODO-->
<item name="Android:focusedMonthDateColor">@Android:color/holo_red_dark</item>
</style>
Ich weiß nicht, welche Attribute für den Datumsauswahldialog verfügbar sind. Es wäre schön, wenn jemand einen Link dazu posten könnte
und nachdem ich den Stil hinzugefügt hatte, nannte ich ihn in meinem Hauptstil als
<item name="Android:datePickerStyle">@style/datepicker</item>
Leider hat das bei mir überhaupt nicht funktioniert.
Versuche dies. Es ist der einfachste und effizienteste Weg
<style name="datepicker" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/primary</item>
</style>
so anrufen
button5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
DialogFragment dialogfragment = new DatePickerDialogTheme();
dialogfragment.show(getFragmentManager(), "Theme");
}
});
public static class DatePickerDialogTheme extends DialogFragment implements DatePickerDialog.OnDateSetListener{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
final Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
//for one
//for two
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_DEVICE_DEFAULT_DARK,this,year,month,day);
//for three
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_DEVICE_DEFAULT_LIGHT,this,year,month,day);
// for four
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_HOLO_DARK,this,year,month,day);
//for five
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_HOLO_LIGHT,this,year,month,day);
//for six
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_TRADITIONAL,this,year,month,day);
return datepickerdialog;
}
public void onDateSet(DatePicker view, int year, int month, int day){
TextView textview = (TextView)getActivity().findViewById(R.id.textView1);
textview.setText(day + ":" + (month+1) + ":" + year);
}
}
folgen Sie diesem, es gibt Ihnen alle Art Datumsauswahlstil (Kopie von diesem)
http://www.Android-examples.com/change-datepickerdialog-theme-in-Android-using-dialogfragment/
Um DatePicker
-Farben (Kalendermodus) auf Anwendungsebene zu ändern, definieren Sie die folgenden Eigenschaften.
<style name="MyAppTheme" parent="Theme.AppCompat.Light">
<item name="colorAccent">#ff6d00</item>
<item name="colorControlActivated">#33691e</item>
<item name="Android:selectableItemBackgroundBorderless">@color/colorPrimaryDark</item>
<item name="colorControlHighlight">#d50000</item>
</style>
Siehe http://www.zoftino.com/Android-datepicker-example für andere DatePicker
benutzerdefinierte Stile
Calendar calendar = Calendar.getInstance();
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), R.style.DatePickerDialogTheme, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
String date = simpleDateFormat.format(newDate.getTime());
}
}, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
datePickerDialog.show();
Und benutze diesen Stil
<style name="DatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/colorPrimary</item>
</style>
Da AlertDialog.THEME
-Attribute veraltet sind, sollten Sie beim Erstellen von DatePickerDialog
einen dieser Parameter für int themeResId
übergeben.
(Ich verwende React Native; targetSdkVersion 22). Ich versuche, das Aussehen eines Dialogfelds für die Datumskalenderauswahl zu ändern. Die akzeptierte Antwort hat für mich nicht funktioniert, aber das hat funktioniert. Ich hoffe, dieser Ausschnitt hilft einigen von Ihnen.
<style name="CalendarDatePickerDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#6bf442</item>
<item name="Android:textColorPrimary">#6bf442</item>
</style>
Erstellen Sie einen neuen Stil
<style name="my_dialog_theme" parent="ThemeOverlay.AppCompat.Dialog">
<item name="colorAccent">@color/colorAccent</item> <!--header background-->
<item name="Android:windowBackground">@color/colorPrimary</item> <!--calendar background-->
<item name="Android:colorControlActivated">@color/colorAccent</item> <!--selected day-->
<item name="Android:textColorPrimary">@color/colorPrimaryText</item> <!--days of the month-->
<item name="Android:textColorSecondary">@color/colorAccent</item> <!--days of the week-->
</style>
Initialisieren Sie dann den Dialog
Calendar mCalendar = new GregorianCalendar();
mCalendar.setTime(new Date());
new DatePickerDialog(mContext, R.style.my_dialog_theme, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
//do something with the date
}
}, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)).show();
Ergebnis: https://i.stack.imgur.com/zlMpg.png