How To Change Android Datepicker Dialog's "dividers" Colors
Solution 1:
You will have to create your own theme that extends THEME_HOLO_DARK. Change basic theme color of android application
Edit: Try something like this
<stylename="testo"parent="@android:style/Widget.DeviceDefault.DatePicker"><itemname="android:divider">@drawable/MyDivider</item></style>And pass the reference to your theme to the constructor
Solution 2:
add this item to your main theme
<itemname="numberPickerStyle">@style/MyApp.NumberPicker</item>set custom divider color in this style
<stylename="MyApp.NumberPicker"parent="Widget.Holo.NumberPicker"><itemname="selectionDivider">@color/white</item></style>EDIT : tested only on HoloEverywhere
Solution 3:
I know it's a late reply but I would like to share my findings with those who experienced or will experience this problem in the future.
I searched many places, and the only solution I found was SimonVT's Pickers.
After implementing the library, it was very easy to change the colors. In numberpicker- the library uses images that can be simply replaced with the desired designs.
This example has three pickers: NumberPicker, DatePicker and TimerPicker.
https://github.com/rodrigobusata/android-pickers
I hope you find it useful.
UPDATED
The above link do not existe anymore, now you must use Material Design https://github.com/wdullaer/MaterialDateTimePicker.
Solution 4:
Please use the below code
Here, dialog is an object of DatePickerDialog.
intdividerId= dialog.getContext().getResources().getIdentifier
("android:id/titleDivider", null, null);
Viewdivider= dialog.findViewById(dividerId);
divider.setBackgroundColor(getResources().getColor(R.color.red));
inttextViewId= dialog.getContext().getResources().getIdentifier
("android:id/alertTitle", null, null);
TextViewtv= (TextView) dialog.findViewById(textViewId);
tv.setTextColor(getResources().getColor(R.color.red));
Solution 5:
funapplyStyLing(timePickerDialog: DatePickerDialog,context: Context) {
try {
var dividerId = timePickerDialog.getContext().getResources().getIdentifier("titleDivider", "id", "android")
val divider = timePickerDialog.findViewById<View>(dividerId)
divider.setBackgroundColor(ContextCompat.getColor(context, R.color.colorDatePicker))
var dividerId1 = timePickerDialog.getContext().getResources().getIdentifier("alertTitle", "id", "android")
val divider1 = timePickerDialog.findViewById<TextView>(dividerId1)
divider1.setTextColor(ContextCompat.getColor(context, R.color.colorDatePicker))
val system = Resources.getSystem()
val hourNumberPickerId = system.getIdentifier("day", "id", "android")
val minuteNumberPickerId = system.getIdentifier("month", "id", "android")
val ampmNumberPickerId = system.getIdentifier("year", "id", "android")
val hourNumberPicker = timePickerDialog.findViewById<View>(hourNumberPickerId) as NumberPicker
val minuteNumberPicker = timePickerDialog.findViewById<View>(minuteNumberPickerId) as NumberPicker
val ampmNumberPicker = timePickerDialog.findViewById<View>(ampmNumberPickerId) as NumberPicker
setNumberPickerDividerColour(hourNumberPicker,context)
setNumberPickerDividerColour(minuteNumberPicker,context)
setNumberPickerDividerColour(ampmNumberPicker,context)
}catch (e:Exception)
{
e.printStackTrace()
}
}
privatefunsetNumberPickerDividerColour(number_picker: NumberPicker,context: Context) {
val count = number_picker.childCount
for (i in0 until count) {
try {
val dividerField = number_picker.javaClass.getDeclaredField("mSelectionDivider")
dividerField.isAccessible = trueval colorDrawable = ColorDrawable(context.getResources().getColor(R.color.colorDatePicker))
dividerField.set(number_picker, colorDrawable)
number_picker.invalidate()
} catch (e: NoSuchFieldException) {
Log.w("setNumberPickerTxtClr", e)
} catch (e: IllegalAccessException) {
Log.w("setNumberPickerTxtClr", e)
} catch (e: IllegalArgumentException) {
Log.w("setNumberPickerTxtClr", e)
}
}
}
Post a Comment for "How To Change Android Datepicker Dialog's "dividers" Colors"