Modification example code for splitting colors in NumberPicker, DatePicker and DatePickerDialog in Android
Preface: In development, in order to apply overall beauty, it is necessary to keep the color tone of the control and the theme color consistent.
For example: Divider line colors for NumberPicker, DatePicker and DatePickerDialog
1. NumberPicker's dividing line color
I wrote the method of splitting the line color of NumberPicker in a tool class to facilitate global calls, and the code is as follows:
public static void setNumberPickerDividerColor(Context context, NumberPicker numberPicker) { NumberPicker picker = numberPicker; Field[] pickerFields = (); for (Field pf : pickerFields) { if (().equals("mSelectionDivider")) { (true); try { //Set the color value of the split line (picker, new ColorDrawable(().getColor(.theme_pink))); } catch (IllegalArgumentException e) { (); } catch ( e) { (); } catch (IllegalAccessException e) { (); } break; } } }
2. DatePicker's dividing line color
Checking the source code of DataPicker, you can see that DatePacker is also implemented by NumberPicker, so the main idea is to modify the color of the NumberPicker split line, the code is as follows:
public static void setDatePickerDividerColor(Context context, DatePicker datePicker){ // Get mSpinners LinearLayout llFirst = (LinearLayout) (0); // Get NumberPicker LinearLayout mSpinners = (LinearLayout) (0); for (int i = 0; i < (); i++) { NumberPicker picker = (NumberPicker) (i); Field[] pickerFields = (); for (Field pf : pickerFields) { if (().equals("mSelectionDivider")) { (true); try { (picker, new ColorDrawable(().getColor(.theme_pink))); } catch (IllegalArgumentException e) { (); } catch ( e) { (); } catch (IllegalAccessException e) { (); } break; } } } }
2. DatePickerDialog's dividing line color
Implementation idea: Get the DatePicker in Dialog to change the color of the segmentation first. The main code is as follows:
DatePickerDialog datePickerDialog = new DatePickerDialog(mContext, 0, listener, year, month, day); ("Select year and month"); (); DatePicker datePicker = (); //Get DatePicker (mContext, datePicker); //Set the color of the split line /*Modify button color This must be after the show or create method*/ Button commitBtn = (DialogInterface.BUTTON_POSITIVE); //Confirm Button (("#e8615e"));
Thank you for reading, I hope it can help you. Thank you for your support for this site!