use*_*624 15 android android-widget android-holo-everywhere
我想使用NumberPicker组件小部件但是在默认的Holo主题中,我需要用橙色替换蓝色,因为这是我造型中的默认颜色.如何更换蓝色和数字的颜色,并保留组件的所有功能?
谢谢
Tom*_*mik 23
不幸的是,你无法设计风格.NumberPicker公共API中不存在样式和样式属性,因此您无法设置它们并更改默认外观.您只能选择明暗主题.
作为解决方案,我建议使用android-numberpicker库代替.该库基本上是从Android源代码中提取的NumberPicker的端口.但它比这更好,它也向后移植NumberPicker到Android 2.x. 图书馆可以很容易地设计风格.
款式分频器调整NPWidget.Holo.NumberPicker风格和selectionDivider和selectionDividerHeight属性.
设置文本NPWidget.Holo.EditText.NumberPickerInputText样式调整样式.
小智 9
<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"></NumberPicker>Run Code Online (Sandbox Code Playgroud)
在drawable文件夹中创建背景
<?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>
Run Code Online (Sandbox Code Playgroud)
小智 2
复制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>
Run Code Online (Sandbox Code Playgroud)
并应用@style/AppTheme作为活动主题。
| 归档时间: |
|
| 查看次数: |
49797 次 |
| 最近记录: |