我想使用NumberPicker组件小部件,但在默认的全息主题中,我需要用橙色替换蓝色,因为这是我的样式中的默认颜色。如何替换蓝色和数字的颜色,并保留组件的所有功能?

谢谢
发布于 2013-02-23 19:01:36
复制library/res/drawable-*/numberpicker_selection_divider.9.png并命名,例如custom_np_sd.9.png。
通过活动主题覆盖默认NumberPicker样式:
<style name="AppTheme" parent="@style/Holo.Theme">
<item name="numberPickerStyle">@style/CustomNPStyle</item>
</style>
<style name="CustomNPStyle" parent="@style/Holo.NumberPicker">
<item name="selectionDivider">@drawable/custom_np_sd</item>
</style>并应用@style/AppTheme作为活动主题。
发布于 2013-02-23 04:48:05
不幸的是,你不能设计它的样式。NumberPicker的样式和样式属性不存在于公共API中,因此您不能设置它们并更改默认外观。您只能在浅色和深色主题之间选择。
作为解决方案,我建议使用android-numberpicker库。这个库基本上是一个从安卓源代码中提取的NumberPicker端口。但比这更好的是,它还将NumberPicker移植到了Android2.x。这个库可以很容易地定义样式。
要设置分隔符的样式,请调整NPWidget.Holo.NumberPicker样式及其selectionDivider和selectionDividerHeight属性。
若要设置文本样式,请调整NPWidget.Holo.EditText.NumberPickerInputText样式。
发布于 2017-03-01 13:11:17
自定义数字选择器预览:

<NumberPicker
android:id="@+id/np"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:background="@drawable/drawablenp"
android:layout_centerVertical="true"/>在名为"drawablenp.xml“的可绘制文件夹中创建后台xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#707070"
android:centerColor="#f8f8f8"
android:endColor="#707070"
android:angle="270"/>
</shape>https://stackoverflow.com/questions/15031624
复制相似问题