变更后的DatePicker定制Numberpicker风格不工作 [英] DatePicker custom Numberpicker Style not working after change

查看:298
本文介绍了变更后的DatePicker定制Numberpicker风格不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的日期选择器,多数民众赞成延长日期选择器。

i have a custom date picker thats extends date picker.

我初始化了一个月的风格:

I have initialized the month style when it loads the component:

private void updateCustomStyle() {
    ViewGroup childPicker = (ViewGroup)
                findViewById(Resources.getSystem().getIdentifier("month" /*rest is:
                day, year*/, "id", "android"));

                EditText textview = (EditText)
                        childPicker.getChildAt(0);
                textview.setTextSize(35);
                textview.setTextColor(Color.GREEN);
                textview.invalidate();

}

这个日期选择器加载完毕后一个月字体大小越大,颜色为绿色。问题发生在一个月后,我滚动到再过一个月,我有我已经在初始化定义的日期更改监听器:

After this the datepicker is loaded the month font size is bigger and the color is green. The problem happens after i scroll the month to another month, i have a date change listener that i've defined upon initialization:

this.init(agora.getYear(), agora.getMonth(), agora.getDate(),
            this.getOnDataChangedListener());

和上的数据变化监听我有这个调用:

And on the data change listener i have this call:

@Override
        public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            updateCustomStyle();
        }

但还是之后,我翻到另一个一个月,又回到原来的风格。对此有什么建议?

But still after i scroll to another month it goes back to the original style. Any suggestions on this?

此方法适用于Android 3.1和4.0。发生在Android 4.1.2和更大的问题。任何想法?

This approach works on Android 3.1 and 4.0. The problems occurs on android 4.1.2 and greater. Any ideas?

推荐答案

做了很多的研究我见过你不能这样做在Android 4.1.X该选择的风格就像你可以在previous版本做了。你可以做的就是创建一个扩展NumberPicker一类,并添加此code:

After done a lot of research i've seen that you cant do that selection style on android 4.1.X like you could do on previous versions. What you can do is to create a class that extends NumberPicker and add this code:

if (child instanceof EditText) {
        ((EditText) child).setTextSize(35);
}

但你仍然无法使用不同的样式选择的号码,所以我所做的是使用simonVT numberpicker(的一些定制后https://github.com/SimonVT/android-numberpicker )至极解决了这个问题。

but still you are not able to use a different style for selected numbers, so what i did is to use simonVT numberpicker (https://github.com/SimonVT/android-numberpicker) wich after some customization solved the problem.

这篇关于变更后的DatePicker定制Numberpicker风格不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆