如何重置数据 numberpicker常用属性

NumberPicker 实现效果不错的数字选择器,可以自定义 的外观颜色。 Special Effects 图形图像处理 238万源代码下载-
&文件名称: NumberPicker
& & & & &&]
&&所属分类:
&&开发工具: Java
&&文件大小: 67 KB
&&上传时间:
&&下载次数: 14
&&提 供 者:
&详细说明:实现效果不错的数字选择器,可以自定义选择器的外观颜色。-Achieve good results in the digital selector, you can customize the appearance of the color picker.
文件列表(点击判断是否您需要的文件,如果是垃圾请在下面评价投诉):
&&android-numberpicker-master&&...........................\.gitignore&&...........................\LICENSE&&...........................\README.md&&...........................\library&&...........................\.......\AndroidManifest.xml&&...........................\.......\build.xml&&...........................\.......\pom.xml&&...........................\.......\project.properties&&...........................\.......\res&&...........................\.......\...\drawable-hdpi&&...........................\.......\...\.............\list_focused_holo.9.png&&...........................\.......\...\.............\list_longpressed_holo.9.png&&...........................\.......\...\.............\list_pressed_holo_dark.9.png&&...........................\.......\...\.............\list_pressed_holo_light.9.png&&...........................\.......\...\.............\list_selector_disabled_holo_dark.9.png&&...........................\.......\...\.............\list_selector_disabled_holo_light.9.png&&...........................\.......\...\.............\np_numberpicker_selection_divider.9.png&&...........................\.......\...\drawable-mdpi&&...........................\.......\...\.............\list_focused_holo.9.png&&...........................\.......\...\.............\list_longpressed_holo.9.png&&...........................\.......\...\.............\list_pressed_holo_dark.9.png&&...........................\.......\...\.............\list_pressed_holo_light.9.png&&...........................\.......\...\.............\list_selector_disabled_holo_dark.9.png&&...........................\.......\...\.............\list_selector_disabled_holo_light.9.png&&...........................\.......\...\.............\np_numberpicker_selection_divider.9.png&&...........................\.......\...\drawable-xhdpi&&...........................\.......\...\..............\list_focused_holo.9.png&&...........................\.......\...\..............\list_longpressed_holo.9.png&&...........................\.......\...\..............\list_pressed_holo_dark.9.png&&...........................\.......\...\..............\list_pressed_holo_light.9.png&&...........................\.......\...\..............\list_selector_disabled_holo_dark.9.png&&...........................\.......\...\..............\list_selector_disabled_holo_light.9.png&&...........................\.......\...\..............\np_numberpicker_selection_divider.9.png&&...........................\.......\...\drawable&&...........................\.......\...\........\item_background_holo_dark.xml&&...........................\.......\...\........\item_background_holo_light.xml&&...........................\.......\...\........\list_selector_background_transition_holo_dark.xml&&...........................\.......\...\........\list_selector_background_transition_holo_light.xml&&...........................\.......\...\layout&&...........................\.......\...\......\number_picker_with_selector_wheel.xml&&...........................\.......\...\values&&...........................\.......\...\......\colors.xml&&...........................\.......\...\......\ids.xml&&...........................\.......\...\......\themes.xml&&...........................\.......\src&&...........................\.......\...\net&&...........................\.......\...\...\simonvt&&...........................\.......\...\...\.......\numberpicker&&...........................\.......\...\...\.......\............\NumberPicker.java&&...........................\.......\...\...\.......\............\Scroller.java&&...........................\pom.xml&&...........................\samples&&...........................\.......\AndroidManifest.xml&&...........................\.......\build.xml&&...........................\.......\pom.xml&&...........................\.......\project.properties&&...........................\.......\res&&...........................\.......\...\drawable-hdpi&&...........................\.......\...\.............\ic_launcher.png&&...........................\.......\...\drawable-ldpi&&...........................\.......\...\.............\ic_launcher.png&&...........................\.......\...\drawable-mdpi&&...........................\.......\...\.............\ic_launcher.png&&...........................\.......\...\layout&&...........................\.......\...\......\activity_dark.xml&&...........................\.......\...\......\activity_light.xml&&...........................\.......\...\......\activity_samples.xml&&...........................\.......\...\values-v11&&...........................\.......\...\..........\themes.xml&&...........................\.......\...\values&&...........................\.......\...\......\strings.xml&&...........................\.......\...\......\themes.xml&&...........................\.......\src&&...........................\.......\...\net&&...........................\.......\...\...\simonvt&&...........................\.......\...\...\.......\numberpicker&&...........................\.......\...\...\.......\............\samples&&...........................\.......\...\...\.......\............\.......\DarkThemeActivity.java&&...........................\.......\...\...\.......\............\.......\LightThemeActivity.java&&...........................\.......\...\...\.......\............\.......\SampleActivity.java
&近期下载过的用户:
&相关搜索:
&输入关键字,在本站238万海量源码库中尽情搜索:
&[] - android的各类view的实现源码,不错的学习代码!
&[] - 实现一个简单的numberpicker控件的Demo使用Android组件NumberPicker定制日期选择器
代码片段(4)
1. [代码]先贴两段神奇的代码
//mHour为NumberPicker对象
//注意 以下两行代码顺序不能变,变后会出现数组下表越界的错误setMaxValue在前
mHour.setMaxValue(todayHourStrs.length-1);
setWrapSelectorWheel();
mHour.setDisplayedValues(todayHourStrs);
//需要先扩大DisplayedValues再setMaxValue,否则会跑出数组下标越界
mHour.setDisplayedValues(hourStrsEmpty);
mHour.setMaxValue(hourStrs.length-1);
setWrapSelectorWheel();
mHour.setDisplayedValues(hourStrs);
private void setWrapSelectorWheel(){
/* setWrapSelectorWheel
* 必须放在setMaxValue后面,因为源码在更改此值的时候要求MaxValue-MinValue&=mSelectorIndices.length(等于3)
* 所以如果MaxValue-MinValue更改了需要重新调用setWrapSelectorWheel
mDay.setWrapSelectorWheel(false);
mHour.setWrapSelectorWheel(false);
mMinute.setWrapSelectorWheel(false);
2. [代码]再来看Android的源码
* Sets whether the selector wheel shown during flinging/scrolling should
* wrap around the {@link NumberPicker#getMinValue()} and
* {@link NumberPicker#getMaxValue()} values.
* By default if the range (max - min) is more than the number of items shown
* on the selector wheel the selector wheel wrapping is enabled.
* &strong&Note:&/strong& If the number of items, i.e. the range (
* {@link #getMaxValue()} - {@link #getMinValue()}) is less than
* the number of items shown on the selector wheel, the selector wheel will
* not wrap. Hence, in such a case calling this method is a NOP.
* @param wrapSelectorWheel Whether to wrap.
public void setWrapSelectorWheel(boolean wrapSelectorWheel) {
final boolean wrappingAllowed = (mMaxValue - mMinValue) &= mSelectorIndices.
if ((!wrapSelectorWheel || wrappingAllowed) && wrapSelectorWheel != mWrapSelectorWheel) {
mWrapSelectorWheel = wrapSelectorW
* Sets the min value of the picker.
* @param minValue The min value inclusive.
* &strong&Note:&/strong& The length of the displayed values array
* set via {@link #setDisplayedValues(String[])} must be equal to the
* range of selectable numbers which is equal to
* {@link #getMaxValue()} - {@link #getMinValue()} + 1.
public void setMinValue(int minValue) {
if (mMinValue == minValue) {
if (minValue & 0) {
throw new IllegalArgumentException("minValue must be &= 0");
mMinValue = minV
if (mMinValue & mValue) {
mValue = mMinV
boolean wrapSelectorWheel = mMaxValue - mMinValue & mSelectorIndices.
setWrapSelectorWheel(wrapSelectorWheel);
initializeSelectorWheelIndices();
updateInputTextView();
tryComputeMaxWidth();
invalidate();
* Sets the values to be displayed.
* @param displayedValues The displayed values.
* &strong&Note:&/strong& The length of the displayed values array
* must be equal to the range of selectable numbers which is equal to
* {@link #getMaxValue()} - {@link #getMinValue()} + 1.
public void setDisplayedValues(String[] displayedValues) {
if (mDisplayedValues == displayedValues) {
mDisplayedValues = displayedV
if (mDisplayedValues != null) {
// Allow text entry rather than strictly numeric entry.
mInputText.setRawInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
mInputText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
updateInputTextView();
initializeSelectorWheelIndices();
tryComputeMaxWidth();
3. [代码]代码分析1
//根据需求,要实现NumberPicker的items动态数量、内容动态变化。所以需要执行以下代码
mHour.setMaxValue(maxValue);
mHour.setDisplayedValues(displayedValues);
//这里要需要注意的是setMaxValue。如果mHour对象原本的displayedValues数组lengths小于即将设置的maxValue。那么,执行setMaxValue就会跑出数组下表越界( java.lang.ArrayIndexOutOfBoundsException)
//相反,如果代码顺序为:
mHour.setDisplayedValues(displayedValues);
mHour.setMaxValue(maxValue);
//那么,这里需要注意setDisplayedValues。如果mHour对象原本的maxValue大于即将甚至的displayedValues数组的lengths,那么,执行setDisplayedValues就会跑出数组下表越界( java.lang.ArrayIndexOutOfBoundsException)
4. [代码]代码分析2
//需求:选择日期的时候,不需要循环(WrapSelectorWheel),
//例如:选择小时 02,下拉一格改为 01 ,在下拉一格就不是23了,而是不能下拉
//要实现这样的功能,NumberPicker提供了一个API:setWrapSelectorWheel,设置为false,即可
mHour.setDisplayedValues(hourStrsEmpty);
mHour.setMaxValue(maxValue);
setWrapSelectorWheel();
mHour.setDisplayedValues(hourStrs);
mHour.setWrapSelectorWheel(false);
//注意,只有mHour对象的maxValue-minValue&=mSelectorIndices.length时。执行setWrapSelectorWheel才会有效。而mSelectorIndices数组的长度为3。
//再注意,设置了setWrapSelectorWheel后需要执行setDisplayedValues。才会更新列表,此列表才不是循环的。所以才会有以上这样的代码顺序。
//由于maxValue&hourStrs.length,所以,需要先执行setDisplayedValues,再由于执行setDisplayedValues如果传入的数组等于原来的数组,就不会更新,所以需要传入一个hourStrsEmpty。hourStrsEmpty数组内容不能有null,长度等于hourStrs
开源中国-程序员在线工具:
相关的代码(1260)
1天前 By 达达的梦想2013
5天前 By IT小香猪
1周前 By 溱
7回/1438阅
1周前 By 啥都别说了
1周前 By 假装是大神
2周前 By 呼啸的代码风
2周前 By 呼啸的代码风
2周前 By liu__ray
2周前 By ARESXIONG
暂无网友评论
若发现bug或建议,欢迎10827人阅读
android(57)
NumberPicker 是用于选择一组预定义好数字的控件。比如时间hour的选择只有0—23有效,则可以通过setMinValue和setMaxValue设定。
使用该控件时需注意他的两个listener和一个formatter:一个listener用于监听当前value的变化;一个listener用于监听该控件的scroll状态;formatter用于格式化显示该控件中的value。下面逐一介绍这几个接口:
1、&:其函数public
void onValueChange(NumberPicker picker, int oldVal, int newVal) ;oldVal前一个选中的值,newValue当前选中的值。
2、:其内部有三种scroll状态SCROLL_STATE_FLING
、&SCROLL_STATE_IDLE 、&SCROLL_STATE_TOUCH_SCROLL。
SCROLL_STATE_TOUCH_SCROLL:用户按下去然后滑动。
SCROLL_STATE_FLING: 相当于是SCROLL_STATE_TOUCH_SCROLL的后续滑动操作。
SCROLL_STATE_IDLE: NumberPicker不在滚动。
格式化显示数字,例如0—23格式化为00 — 23 。具体的格式在format函数中规定,如下代码:
public String format(int value) {
String tmpStr = String.valueOf(value);
if (value & 10) {
tmpStr = &0& + tmpS
return tmpS
}value值在0—23之间,小于10的数在前面加上“0”。
接下来就是一步一步完成上述功能:
1、创建布局文件widget_number_picker_layout.xml
&?xml version=&1.0& encoding=&utf-8&?&
&RelativeLayout xmlns:android=&/apk/res/android&
android:layout_width=&match_parent&
android:layout_height=&match_parent& &
&NumberPicker
android:id=&@+id/show_num_picker&
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:layout_alignParentLeft=&true&
android:layout_alignParentTop=&true&
android:layout_marginLeft=&71dp&
android:layout_marginTop=&141dp& /&
&/RelativeLayout&2、创建activity——WidgetNumPickerActivity
package com.xy.zt.
import android.app.A
import android.os.B
import android.util.L
import android.widget.NumberP
import android.widget.NumberPicker.F
import android.widget.NumberPicker.OnScrollL
import android.widget.NumberPicker.OnValueChangeL
import android.widget.T
public class WidgetNumPickerActivity extends Activity implements
OnValueChangeListener, Formatter, OnScrollListener {
private NumberPicker mNumberP
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.widget_number_picker_layout);
private void init() {
mNumberPicker = (NumberPicker) findViewById(R.id.show_num_picker);
mNumberPicker.setFormatter(this);
mNumberPicker.setOnValueChangedListener(this);
mNumberPicker.setOnScrollListener(this);
mNumberPicker.setMaxValue(23);
mNumberPicker.setMinValue(0);
mNumberPicker.setValue(10);
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
Log.i(&tag&, &oldValue:& + oldVal + & newValue: & + newVal);
Toast.makeText(
&number changed --& oldValue: & + oldVal + & ; newValue: &
+ newVal, Toast.LENGTH_SHORT).show();
public String format(int value) {
String tmpStr = String.valueOf(value);
if (value & 10) {
tmpStr = &0& + tmpS
return tmpS
public void onScrollStateChange(NumberPicker view, int scrollState) {
switch (scrollState) {
case OnScrollListener.SCROLL_STATE_FLING:
Toast.makeText(this, &scroll state fling&, Toast.LENGTH_LONG)
case OnScrollListener.SCROLL_STATE_IDLE:
Toast.makeText(this, &scroll state idle&, Toast.LENGTH_LONG).show();
case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
Toast.makeText(this, &scroll state touch scroll&, Toast.LENGTH_LONG)
其中一个状态的效果图如下:
3、下面代码完善整个工程,如下有不清楚的内容参见
在ViewData.java中添加如下内容:
public static final int NUMBER_PICKER_ID = TIME_PICKER_ID + 1;
public static final String NUMBER_PICKER_NAME = &NumberPicker&;
private static final ViewData mNumPicker = new ViewData(NUMBER_PICKER_NAME,
NUMBER_PICKER_ID);
View_Datas.add(mNumPicker);
在WidgetsAdapter的handleItemClick函数中添加如下内容:
case ViewData.NUMBER_PICKER_ID:
intent.setClass(mContext, WidgetNumPickerActivity.class);
mContext.startActivity(intent);
NumberPicker控件就学到这,下一个控件DigitalClock。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:105502次
积分:1971
积分:1971
排名:第12843名
原创:88篇
评论:21条
(1)(2)(3)(4)(3)(1)(2)(5)(1)(2)(1)(4)(13)(13)(17)(12)(3)(1)(1)(2)(1)(1)(2)(3)(2)(1)numberpicker数字颜色
只看楼主 倒序阅读楼主
//LCD时间显示
QLCDNumber *m_pLcdTime = new QLCDNumber(this);
//设置显示几个数字
m_pLcdTime-&setDigitCount(19);
//设置数字字体:Outline,轮廓突出,颜色为背景色 ...
1.利于系统自带的颜色类 如TextView1.setTextColor(Android.graphics.Color.RED); 2.数字颜色表示法 TextView1.setTextColor(0xffff00ff); 3.自定义颜色 TextView1.setTextColor(this.getResources().getColor(R.drawable.red)) ...
1.在android中经常看到设置的颜色为八位的十六进制的颜色值,例如: 1 2 3 public static final class color {
public static final int lightblue=0x7f040; } 或者在Java中tx.setTextColor(0xffff00f); 说明: 0xffff00ff是int类型的数据,分组 ...
1.利于系统自带的颜色类 如TextView1.setTextColor(android.graphics.Color.RED); // 布局文件中:android:textColor=&@android:color/white& 详见Android源码base/core/res/res/values/colors.xml 2.数字颜色 ...
1.利于系统自带的颜色类 如TextView1.setTextColor(Android.graphics.Color.RED); 2.数字颜色表示法 TextView1.setTextColor(0xffff00ff); 3.自定义颜色 TextView1.setTextColor(this.getResources().getColor(R.drawable.red)) ...
写文字在Android模拟器中的方法 法一: main.xml配置文件: &TextView android:id=&@+id/tv& android:layout_width=&fill_parent& android:layout_height=&wrap_content& android:textSi ...
互联网充斥着枯燥的设计,惠普.IBM.戴尔.微软,以及其他数不尽的网站(相似的布局,相似的配色).可能有人会说通过这样一种标准化的界面可以使浏览更方便,而事实上这些网站带给用户一种很世俗的体验,并不能与访客产生一种积极的联系. 面对这种单调的设计,有一种解决方法,就是使用颜色.可能没有其他设计元素能像颜色一样能影响人们对世界(比如网站,比如家居装潢)的感受.颜色可以瞬间改变 ...
互联网充斥着枯燥的设计,惠普.IBM.戴尔.微软,以及其他数不尽的网站(相似的布局,相似的配色).可能有人会说通过这样一种标准化的界面可以使浏览更方便,而事实上这些网站带给用户一种很世俗的体验,并不能与访客产生一种积极的联系.面对这种单调的设计,有一种解决方法,就是使用颜色.可能没有其他设计元素能像颜色一样能影响人们对世界(比如网站,比如家居装潢)的感受.颜色可以瞬间改变 ...
通过putty或者securecrt连到linux服务器,使用vi编辑*.php 或*.c文件时, 蓝色的注释很淡,看不清,看起来很费眼 效果如下 我本身有习惯于默认配色,不想修改配色方案,只想把看不清蓝色的注释换掉,修改成目录的蓝色 翻了翻相关资料,大部分都是修改配色方案,最后发现可以通过hi命令来修改注释的颜色. hi指令使用方法 设置关键字为蓝色非粗体 :hi Ide ...
/363.html 通过putty或者securecrt连到linux服务器,使用vi编辑*.php 或*.c文件时, 蓝色的注释很淡,看不清,看起来很费眼 效果如下 我本身有习惯于默认配色,不想修改配色方案,只想把看不清蓝色的注释换掉,修改成目录的蓝色 翻了翻相关资料,大部分都是修改配色方案,最后发现可以通过hi命令来修改注释的颜色. ...
在Linux shell或者平时echo输出时有时为了区分某些字符串的重要性,往往对其输出内容添加颜色 以醒目区分输出字符串: 语法格式: echo -e &33[字背景颜色:文字颜色m 醒目字符串 33[0m& eg: [ scripts]# echo -e &I 33[43;31mLOVE33[0m CHINA&quot ...
通过putty或者securecrt连到linux服务器,使用vi编辑*.php 或*.c文件时,
蓝色的注释很淡,看不清,看起来很费眼
我本身有习惯于默认配色,不想修改配色方案,只想把看不清蓝色的注释换掉,修改成目录的蓝色
翻了翻相关资料,大部分都是修改配色方案,最后发现可以通过hi命令来修改注释的颜色.
hi指令使用方法
设置关键字 ...
转自:/nancy0302/item/05fe29c2bc21d41ab77a2442 1.在android中经常看到设置的颜色为八位的十六进制的颜色值,例如: 或者在Java中 说明: 颜色和不透明度 (alpha) 值以十六进制表示法表示.任何一种颜色的值范围都是
对于 alpha, 表达式顺序是& 2.Android中 ...
网页颜色模式 维基百科,自由的百科全书 跳转到: 导航, 搜索 网页颜色模式是在互联网上制作网页时,选择各种颜色的方法,可以用三组十六进制数字表示,也可以用英语颜色名称表示. 目录 [隐藏] 1 十六进制数字表示方法 2 HTML名称 3 X11 名称 4 网页安全颜色 5 真正安全颜色 6 参见 7 外部链接 [编辑] 十六进制数字表示方法 在超文本置位语言(HTML)和 ...
/bluestorm/p/3644669.html 1.在android中经常看到设置的颜色为八位的十六进制的颜色值,例如: 1 2 3 public static final class color {
public static final int lightblue=0x7f040000; } 或者在Java中tx. ...
原文: /index.php/archives/179/
瞎折腾移动端的项目已经很长一段时间了,并不像其它企业一样,可以有项目组去完成,基本都是一个人瞎尝试,时而web,时而web app.过了这段岁月,也不晓得自己忙了啥.总叫别人去总结,让别人学会总结,也该为自己总结总结了.也为了团队之间更好的知识共享吧.如何开发移动端就跟如何 ...
说实话,我们这次开发移动端的项目,整个项目组的人都是第一次,最初立项的时候为是选择native app和web app还争论了一番,最后综合考虑,我们选择了web(我们选择了h5)开发.但从这两种开发模式的特点来说,从它们诞生之日起就开始了不断的争论,孰好孰坏,本文不作探讨,只是简单罗列下本人开发遇到的问题和最终的解决方案.
1. 响应式web设计 说到这个,移动开 ...
说实话,我们这次开发移动端的项目,整个项目组的人都是第一次,最初立项的时候为是选择native app和web app还争论了一番,最后综合考虑,我们选择了web(我们选择了h5)开发.但从这两种开发模式的特点来说,从它们诞生之日起就开始了不断的争论,孰好 孰坏,本文不作探讨,只是简单罗列下本人开发遇到的问题和最终的解决方案. 1. 响应式web设计 说 到这个,移动开发面 ...
先看一下效果: 在点击OK键之后,开始倒计时. 实现步骤 1.新建Android工程&CountdownView& 2.自定义Drawable 自定义View并没有直接的用户交互,简化起见,可以自定义实现一个drawable,作为ImageView的背景 观察一下View的构成,分为几个部分: 1. 外围圆环边界 2. 进度条 3. 内部圆形背景 4.
/homepage/shredderyin/emacs_elisp.html Emacs 具有超强的扩展性.这是当今没有任何其它编辑器可以比拟 的强大特点.这里介绍一些很方便的 Emacs Lisp 扩展. 有链接的文件可能不是 Emacs 自带的,你需要下载el文件到你的 load-path 中的一个目录里. 所有文件可以点击链 ...}

我要回帖

更多关于 numberpicker 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信