问题描述
在最近的Android版本,数量采摘使用蓝色分频器时绘制的(参见图片下文)。
我想改变这种颜色。是否有一个工作的解决方案?或者是一个库,打包NumberPicker的更新版本,允许自定义分隔颜色?
我已经试过的Android numberpicker 但我得到的运行时错误(见下文),由于一些code从试图访问一个不存在的资源ID库。
android.content.res.Resources $ NotFoundException:资源编号为0x0
在android.content.res.Resources.getValue(Resources.java:1123)
在android.content.res.Resources.loadXmlResourceParser(Resources.java:2309)
在android.content.res.Resources.getLayout(Resources.java:939)
在android.view.LayoutInflater.inflate(LayoutInflater.java:395)
在net.simonvt.numberpicker.NumberPicker< INIT>(NumberPicker.java:635)
在net.simonvt.numberpicker.NumberPicker< INIT>(NumberPicker.java:560)
在net.simonvt.numberpicker.NumberPicker< INIT>(NumberPicker.java:550)
在此基础上( http://stackoverflow.com/a /二百九十一万五千四百八十零分之二千○二十九万一千四百一十六虽然它是关于的DatePicker)有几种方法:
-
自己写的NumberPicker没有mSelectionDivider及其分支机构或者使用维克拉姆的反向移植。在最后一种情况:
- 从 github上从LIB下载
-
变化绘制在RES /绘制-XXX / np_numberpicker_selection_divider.9.png:
- 要透明(或其他).9.png
- 创建的RES / np_numberpicker_selection_divider.xml造型线资源绘制(与
0dp
高度或透明色)。
-
或从的OnDraw(Canvas)的方法在如果(mSelectionDivider!= NULL)分公司href="https://github.com/SimonVT/android-numberpicker/blob/master/library/src/net/simonvt/numberpicker/NumberPicker.java">NumberPicker.java像这里
-
使用反射来访问
私人最终场mSelectionDivider
(详细资料:https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/NumberPicker.java) - 如见修改这里。我用反射,但它不是最好的解决办法。
On recent android versions, number pickers use a blue divider when drawn (cf. image below).
I would like to change this color. Is there a working solution? or perhaps a library that package an updated version of NumberPicker that allows customizing the divider color?
I have tried android-numberpicker but I get an error (see below) at runtime due to some code from the library that tries to access to a resource id that does not exist.
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1123)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2309)
at android.content.res.Resources.getLayout(Resources.java:939)
at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
at net.simonvt.numberpicker.NumberPicker.<init>(NumberPicker.java:635)
at net.simonvt.numberpicker.NumberPicker.<init>(NumberPicker.java:560)
at net.simonvt.numberpicker.NumberPicker.<init>(NumberPicker.java:550)
Based on this (http://stackoverflow.com/a/20291416/2915480 although it's about DatePicker) there are several ways:
Write your own NumberPicker without mSelectionDivider and its affiliates or use backported by Vikram. In last case:
- download from lib from github
change drawable in res/drawable-xxx/np_numberpicker_selection_divider.9.png:
- to transparent (or whatever) .9.png
- create np_numberpicker_selection_divider.xml shape line resource in res/drawable (with
0dp
height or transparent color).
OR remove
if (mSelectionDivider != null)
branch from onDraw(Canvas) method in NumberPicker.java like here
Use reflection to access
private final field mSelectionDivider
(details: https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/NumberPicker.java) - e.g. see modification here. I used reflection but it's not the best solution.
这篇关于更改NumberPicker分颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!