How to hide the previous and next numbers in a number picker?

故事扮演 提交于 2019-12-30 11:53:08

问题


Summary

I'm attempting to hide the previous and next numbers in an Android number picker. Additionally, I'm extending the NumberPicker class so that I can change the font size and color. I've noticed that I could potentially change the value:

private static final int MODIFIED_SELECTOR_WHEEL_ITEM_COUNT = 3;

I'm just not sure how I could override a static final value.

Default number picker:

Desired Modified Number Picker I would like to make the number picker look like so, with the animation in tact:

Extended Number Picker class:

public class CustomStatNumberPicker extends android.widget.NumberPicker{
    private static final int MODIFIED_SELECTOR_WHEEL_ITEM_COUNT = 1;

    public CustomStatNumberPicker(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void addView(View child) {
        super.addView(child);
        updateView(child);
    }

    @Override
    public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) {
        super.addView(child, index, params);
        updateView(child);
    }

    @Override
    public void addView(View child, android.view.ViewGroup.LayoutParams params) {
        super.addView(child, params);
        updateView(child);
    }

    private void updateView(View view) {
        if(view instanceof EditText){
            ((EditText) view).setTextSize(40);
            ((EditText) view).setTextColor(Color.parseColor("#FFFFFF"));
        }
    }

}

TL;DR; How do I hide the previous and next number picker values? Either through overriding a method, or modifying the extended class like I've already done.

Thank you in advance.


回答1:


you could modify the drawing routine to skip over any index that isn't in the center row. Try changing the conditions at line 1478.



来源:https://stackoverflow.com/questions/40495601/how-to-hide-the-previous-and-next-numbers-in-a-number-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!