Android gets the control in DatePicker through reflection and changes its color. androiddatepicker

Source: Internet
Author: User
Tags getcolor

Android gets the control in DatePicker through reflection and changes its color. androiddatepicker

 

 

In the end, the color of the middle part is successfully changed.

 

 

 

Private void setDatePickerDividerColor (DatePicker datePicker) {// Divider changing: // get mSpinners LinearLayout llFirst = (LinearLayout) datePicker. getChildAt (0); // obtain NumberPicker LinearLayout mSpinners = (LinearLayout) llFirst. getChildAt (0); for (int I = 0; I <mSpinners. getChildCount (); I ++) {NumberPicker picker = (NumberPicker) mSpinners. getChildAt (I); Field [] pickerFields = NumberPicker. class. getDeclaredFields (); for (Field pf: pickerFields) {pf. setAccessible (true); String pfString = pf. getName (); try {if (pfString. equals ("mSelectionDivider") {pf. set (picker, new ColorDrawable (Color. parseColor ("# ffffff"); // sets the split line color break;} else if (pfString. equals ("mInputText") {EditText mInputText = (EditText) pf. get (picker); // obtain the mInputText object corresponding to this attribute. setTextColor (view. getResources (). getColor (R. color. white); break;} else if (pfString. equals ("mSelectorWheelPaint") {Paint mPaint = (Paint) pf. get (picker); // obtain the object mPaint corresponding to this attribute. setColor (view. getResources (). getColor (R. color. white); break;} else if (pfString. equals ("mVirtualButtonPressedDrawable") {pf. set (picker, new ColorDrawable (Color. parseColor ("# ffffff"); break ;}} catch (IllegalArgumentException e) {e. printStackTrace ();} catch (Resources. notFoundException e) {e. printStackTrace ();} catch (IllegalAccessException e) {e. printStackTrace ();}}}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.