码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-08-02 18:10:04      阅读:1485      评论: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

(2)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!