到最后也只是成功改变了中间部分的颜色。

   private void setDatePickerDividerColor(DatePicker datePicker) {
// Divider changing: // 获取 mSpinners
LinearLayout llFirst = (LinearLayout) datePicker.getChildAt(); // 获取 NumberPicker
LinearLayout mSpinners = (LinearLayout) llFirst.getChildAt();
for (int i = ; 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")));//设置分割线颜色
break;
} else if (pfString.equals("mInputText")) {
EditText mInputText = (EditText) pf.get(picker);//获得该属性对应的对象
mInputText.setTextColor(view.getResources().getColor(R.color.white));
break;
} else if (pfString.equals("mSelectorWheelPaint")) {
Paint mPaint = (Paint) pf.get(picker);//获得该属性对应的对象
mPaint.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();
}
}
}
}

Android 通过反射获取DatePicker 中的控件,并改变其颜色的更多相关文章

  1. 获取fragment中的控件的写法

    package com.example.baoxiu.fragment;import com.example.baoxiu.R;import com.example.baoxiu.Register;i ...

  2. C# 通过反射获取winform上的控件

    比如获取Button按钮: System.Reflection.FieldInfo[] fieldInfo = form.GetType().GetFields(System.Reflection.B ...

  3. fragment中获取activity中的控件

  4. asp.net 前台js和后台得到FormView中的控件,以TextBox为例

    一.前台js获取FormView中的控件 js得到前端控件的ID,比如TextBox(这里设置其ID为TextBox1),大家都知道,是document.getElementById("&l ...

  5. 如何获取Android应用的packageName和ActivityName,识别应用中的控件

    1.获取Android应用的packageName和ActivityName A:adb logcat >log.txt 在log中搜索package B:adb shell  logcat | ...

  6. android中ListView控件&&onItemClick事件中获取listView传递的数据

    http://blog.csdn.net/aben_2005/article/details/6592205 本文转载自:android中ListView控件&&onItemClick ...

  7. Android 中常见控件的介绍和使用

    1 TextView文本框 1.1 TextView类的结构 TextView 是用于显示字符串的组件,对于用户来说就是屏幕中一块用于显示文本的区域.TextView类的层次关系如下: java.la ...

  8. Android中ListView控件的使用

    Android中ListView控件的使用 ListView展示数据的原理 在Android中,其实ListView就相当于web中的jsp,Adapter是适配器,它就相当于web中的Servlet ...

  9. Android中常用控件及属性

    在之前的博客为大家带来了很多关于Android和jsp的介绍,本篇将为大家带来,关于Andriod中常用控件及属性的使用方法,目的方便大家遗忘时,及时复习参考.好了废话不多讲,现在开始我们本篇内容的介 ...

随机推荐

  1. qq跳转

    给<a href="http://wpa.qq.com/msgrd?v=3&uin=1061214467&site=qq&menu=yes">& ...

  2. Python学习笔记【Supervisor】:使用Supervisor监控Tornado进程

    Linux常见应用服务配置模式nginx和supervisor:采用主配置文件+项目配置文件 安装(如果使用pip安装注意看是否需要指定使用python2版本) 第一步:在Linux中使用apt-ge ...

  3. [Swift]LeetCode140. 单词拆分 II | Word Break II

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add space ...

  4. [Swift]LeetCode332. 重新安排行程 | Reconstruct Itinerary

    Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], r ...

  5. [Swift]LeetCode628. 三个数的最大乘积 | Maximum Product of Three Numbers

    Given an integer array, find three numbers whose product is maximum and output the maximum product. ...

  6. [Swift]LeetCode769. 最多能完成排序的块 | Max Chunks To Make Sorted

    Given an array arr that is a permutation of [0, 1, ..., arr.length - 1], we split the array into som ...

  7. [Swift]LeetCode1011. 在 D 天内送达包裹的能力 | Capacity To Ship Packages Within D Days

    A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...

  8. Python内置函数(68)——__import__

    英文文档: __import__(name, globals=None, locals=None, fromlist=(), level=0) This function is invoked by ...

  9. 利用NPOI生成word文档(c#)

    WordTest.aspx.cs using System; using System.IO; using System.Text; using System.Web; using System.We ...

  10. 『没有上司的舞会 树形DP』

    树形DP入门 有些时候,我们需要在树形结构上进行动态规划来求解最优解. 例如,给定一颗\(N\)个节点的树(通常是无根树,即有\(N-1\)条无向边),我们可以选择任意节点作为根节点从而定义出每一颗子 ...