改变NumberPicker文字,分割线的颜色

来源:互联网 发布:淘宝能买到氰化钾吗 编辑:程序博客网 时间:2024/05/16 12:32

参考文章:
http://blog.csdn.net/billy_zuo/article/details/70224721
前几天由于要修改软件主题颜色,而前面的开发人员用了系统的DatePickerDialog,由于时间较紧,对我这样的初学者来说自定义一个Dialog需要的时间可能不是一点点。。。。于是一番搜索后,总结出如下方法,做个笔记

/**  *  * 设置时间选择器的颜色  * @param datePicker  */  private void setDatePickerDividerColor(DatePicker datePicker){      LinearLayout llFirst = (LinearLayout) datePicker.getChildAt(0);      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) {            if (pf.getName().equals("mSelectionDivider")) {                 pf.setAccessible(true);                 try {                   pf.set(picker, new ColorDrawable                       (getResources().getColor(R.color.crimson)));                 } catch (IllegalArgumentException e) {                     e.printStackTrace();                 } catch (Resources.NotFoundException e) {                     e.printStackTrace();                 } catch (IllegalAccessException e) {                     e.printStackTrace();                 }             }//  此处看到别的大神在修改字体颜色的时候做了这个判断,但不是很明白,试了下不做这个//  也能用。。。//           if (!(picker.getChildAt(0) instanceof EditText) &&     //          !(picker.getChildAt(0) instanceof TextView)){//                  return;//           }             if (pf.getName().equals("mSelectorWheelPaint")){                 pf.setAccessible(true);                 try {                        ((Paint)pf.get(picker)).setColor                            (getResources().getColor(R.color.white));                        ((EditText)picker.getChildAt(0)).setTextColor                            (getResources().getColor(R.color.white));                        picker.invalidate();                    } catch (IllegalAccessException e) {                        e.printStackTrace();                    }                }            }        }    }

以上就是在下在前人的经验上总结的代码了,不对之处,多多指教

阅读全文
0 0
原创粉丝点击