8

有没有办法增加褪色边缘或更改数字选择器的顶部/底部文本 alpha?我能够扩展 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();
            }
        }
    }
}

设计

在此处输入图像描述

到目前为止的结果

在此处输入图像描述

编辑:最终使用了这个

4

0 回答 0