fun applyStyLing(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()
}
}
private fun setNumberPickerDividerColour(number_picker: NumberPicker,context: Context) {
val count = number_picker.childCount
for (i in 0 until count) {
try {
val dividerField = number_picker.javaClass.getDeclaredField("mSelectionDivider")
dividerField.isAccessible = true
val 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)
}
}
}