有没有办法增加数字选择器的渐弱边缘或更改顶部/底部文本字母?我能够扩展NumberPicker类并更改数字选择器轮的alpha但是一旦我开始滚动alpha也会应用到中心文本。正如你所看到的,我选择了小时值并且alpha应用于所有文本。我希望alpha只是顶部和底部的数字。我有什么方法可以做到这一点。 ?
private void updateTextAttributes(String fontName) {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (child instanceof EditText) {
try {
Field selectorWheelPaintField = NumberPicker.class.getDeclaredField("mSelectorWheelPaint");
selectorWheelPaintField.setAccessible(true);
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/SFUIDisplay-" + fontName + ".ttf");
Paint wheelPaint = ((Paint) selectorWheelPaintField.get(this));
wheelPaint.setTextSize(mTextSize);
wheelPaint.setTypeface(typeface);
wheelPaint.setColor(mTextColor);
wheelPaint.setAlpha(50); //It does change alpha in the beginning but once I scroll then it also changes center text color
EditText editText = ((EditText) child);
editText.setTextColor(mTextColor);
editText.setTextSize(pixelsToSp(getContext(), mTextSize));
editText.setTypeface(typeface);
editText.setAlpha((float) 1.0);
invalidate();
break;
} catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException e) {
e.printStackTrace();
}
}
}
}
设计
到目前为止的结果
编辑:使用此library
结束