Android numberpicker control modifies split line color and font color size

Source: Internet
Author: User

(1) Rewrite Numberpicker has reached the modified display font color size

 Public classTextcolornumberpickerextendsNumberpicker { PublicTextcolornumberpicker (Context context) {Super(context); }      PublicTextcolornumberpicker (Context context, AttributeSet attrs) {Super(context, attrs); }      PublicTextcolornumberpicker (context context, AttributeSet attrs,intdefstyleattr) {        Super(context, attrs, defstyleattr); } @Override Public voidAddView (View child) {Super. AddView (child);    Updateview (child); } @Override Public voidAddView (View Child,intindex, Android.view.ViewGroup.LayoutParams params) {        Super. AddView (Child, index, params);    Updateview (child); } @Override Public voidAddView (View child, Android.view.ViewGroup.LayoutParams params) {Super. AddView (Child, params);    Updateview (child); }      Public voidUpdateview (view view) {if(ViewinstanceofEditText) {            //here to modify the properties of the display font, mainly modify the color((EditText) view). SetTextColor (Color.parsecolor ("#BAA785"));        }    }}

(2) To modify the split line color, you need to animate the color by reflection after the control is initialized.

Note: The following method is called after the Numberpicker setdisplayedvalues call:

1 Private voidSetnumberpickerdividercolor (Numberpicker numberpicker) {2Numberpicker Picker =Numberpicker;3field[] Pickerfields = Numberpicker.class. Getdeclaredfields ();4          for(Field pf:pickerfields) {5             if(Pf.getname (). Equals ("Mselectiondivider")) {6Pf.setaccessible (true);7                 Try {8                     //set color value transparency for split lines9Pf.set (Picker,NewColordrawable ( This. Getresources (). GetColor (Android. (r.color.transparent) ));Ten}Catch(IllegalArgumentException e) { One e.printstacktrace (); A}Catch(resources.notfoundexception e) { - e.printstacktrace (); -}Catch(illegalaccessexception e) { the e.printstacktrace (); -                 } -                  Break; -             } +         } -}

(3) Use Numberpicker Note:

1 // Disable click to open keyboard 2 picker.setdescendantfocusability (numberpicker.focus_block_descendants); 3 // set the maximum value, the minimum value has reached the display of all eligible values 4 picker.setmaxvalue (array.length-1); 5 picker.setminvalue (0);

(4) The List is converted to array[] so that Numberpicker settings setdisplayedvalues (string[]):

New string[list.size ()];list.toarray (array);

Connection: http://my.oschina.net/yaly/blog/532153

Android numberpicker control modifies split line color and font color size

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.