How to hide the previous and next numbers in a num

2019-02-20 01:50发布

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:

Default Number Picker

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

Modified Number Picker

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条回答
smile是对你的礼貌
2楼-- · 2019-02-20 02:12

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.

查看更多
登录 后发表回答