android自定义numberpicker,Android 中对 Dialog 以及 NumberPicker 的配置 – 热爱改变生活...

目标:弹出一个对话框

客户:给我一个选择时间的对话框吧。

程序猿:好

70a0a650baffb55ed495a4197ec30ec1.png

客户:呵呵

进化①

程序猿:Dialog 真难看,设置一下样式吧。

public class SumileNumberPickerDialog extends AlertDialog

首先我自定义了一个类,继承了 AlertDialog,然后我们就看到了他的构造方法

fff2883cb89dab0a07e2343c6a28b83e.png

程序猿:窝草,这里有设置 Theme 的地方哎~

于是,程序猿欢快的写下了下面的代码:

e64c81b7d6a7a8332d1bfac4cf306c24.png

一运行:

af4e0b532cea161676c57cdea544de49.png

程序猿:黑了个嘿嘿嘿,dialog 好了,里面的 numberPicker 怎么可以那么丑!

进化②

程序猿:既然 Dialog 可以设置 Theme,那么 NumberPicker 是不是也可以呢?

呵:

A widget that enables the user to select a number form a predefined range. There are two flavors of this widget and which one is presented to the user depends on the current theme.

If the current theme is derived from android.R.style.Theme the widget presents the current value as an editable input field with an increment button above and a decrement button below. Long pressing the buttons allows for a quick change of the current value. Tapping on the input field allows to type in a desired value.

If the current theme is derived from android.R.style.Theme_Holo or android.R.style.Theme_Holo_Light the widget presents the current value as an editable input field with a lesser value above and a greater value below. Tapping on the lesser or greater value selects it by animating the number axis up or down to make the chosen value current. Flinging up or down allows for multiple increments or decrements of the current value. Long pressing on the lesser and greater values also allows for a quick change of the current value. Tapping on the current value allows to type in a desired value.

For an example of using this widget, see android.widget.TimePicker.

看到没,和系统的主题有关~

可是,我系统主题是对的啊

3917cec3656deb2ee8d74d299e68b176.png

哎,我记得 Activity 也可以设置 Theme 啊,Dialog 是依赖于 Activity 的,那 Dialog 的样式是不是因为 Activity 呢?

窝草

6e9520b46e7f820fe56ef93a6242ddd8.png

谁干的!这里加毛 Theme。。

去掉之后的效果:

d39ca3ca16d844a046449534def9ed3d.png

结果

客户:嘿嘿嘿

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值