问题
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