在NumberPicker中显示更多号码 [英] Display more numbers in NumberPicker

查看:175
本文介绍了在NumberPicker中显示更多号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个问题,第一个是删除NumberPicker中的分隔线,而我正在扩展Android中的NumberPicker以解决此问题,如下所示:

I have two issues, first one is removing the divider in the NumberPicker and I'm extending the NumberPicker in Android to solve this issue, like this:

import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.widget.NumberPicker;

import java.lang.reflect.Field;


public class ExtendedNumberPicker extends NumberPicker {

    public ExtendedNumberPicker(Context context, AttributeSet attrs) {
        super(context, attrs);

        Class<?> numberPickerClass = null;
        try {
            numberPickerClass = Class.forName("android.widget.NumberPicker");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        Field selectionDivider = null;
        try {
            selectionDivider = numberPickerClass.getDeclaredField("mSelectionDivider");
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }

        try {
            selectionDivider.setAccessible(true);
            selectionDivider.set(this, null);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (Resources.NotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}

我的另一个问题是,我找不到任何方式显示超过3个元素,如下面的UI:

My other issue is that I didn't find any way to display more than 3 elements like the below UI:

推荐答案

设置删除分隔线

<NumberPicker
   ...
   android:theme="@style/DefaultNumberPickerTheme" />

style.xml

style.xml

<style name="DefaultNumberPickerTheme" parent="AppTheme">
        <item name="colorControlNormal">@color/transparent</item>
</style>

对于另一部分:检出希望这会有所帮助!

这篇关于在NumberPicker中显示更多号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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