首页 > 其他 > 详细

NumberPicker设置宽度,设置文字颜色

时间:2015-08-02 18:08:19      阅读:500      评论:0      收藏:0      [点我收藏+]

修改宽度

wheel = (NumberPicker) findViewById(R.id.info_wheel_province);
wheel.setLayoutParams(new LinearLayout.LayoutParams(deviceSize.x >> 1, LinearLayout.LayoutParams.WRAP_CONTENT));

修改文字颜色

public static boolean setNumberPickerTextColor(NumberPicker numberPicker, int color) {
        boolean result = false;
        final int count = numberPicker.getChildCount();
        for (int i = 0; i < count; i++) {
            View child = numberPicker.getChildAt(i);
            if (child instanceof EditText) {
                try {
                    Field selectorWheelPaintField = numberPicker.getClass()
                            .getDeclaredField("mSelectorWheelPaint");
                    selectorWheelPaintField.setAccessible(true);
                    ((Paint) selectorWheelPaintField.get(numberPicker)).setColor(color);
                    ((EditText) child).setTextColor(color);
                    numberPicker.invalidate();
                    result = true;
                } catch (NoSuchFieldException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }

效果

技术分享

 

NumberPicker设置宽度,设置文字颜色

原文:http://www.cnblogs.com/xirtam/p/4696266.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!