我想在Android上实现这一结果:
我已尝试使用LinearGradient
Shader
,但它只是在EditText
背景而不是文字中应用渐变效果。
你能帮帮我吗?
Edit1:添加代码
public class CustomEditText extends AppCompatEditText {
public CustomEditText(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
@ColorInt int startColor = ResourcesCompat.getColor(
getResources(), android.R.color.transparent, getContext().getTheme());
@ColorInt int endColor = ResourcesCompat.getColor(
getResources(), android.R.color.black, getContext().getTheme());
LinearGradient gradient = new LinearGradient(0, 0, getWidth(), 0, startColor, endColor, Shader.TileMode.MIRROR);
Paint paint = new Paint(Paint.DITHER_FLAG);
paint.setShader(gradient);
super.onDraw(canvas);
}
}