先上效果图:
第一步:创建带有文字的bitmap
Bitmap bitmap = Bitmap.createBitmap(240, 240, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE);
Paint paint = new Paint();
paint.setColor(Color.GRAY);
paint.setAlpha(80);
paint.setAntiAlias(true);
paint.setTextAlign(Paint.Align.LEFT);
paint.setTextSize(40);
Path path = new Path();
path.moveTo(30, 150);
path.lineTo(300, 0);
canvas.drawTextOnPath("无名科技", path, 0, 30, paint);
第二步:创建bitmapDrawable,并使其填充方式为重复填充
BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
bitmapDrawable.setDither(true);
第三步:为view设置水印背景
view.setBackgroundDrawable(bitmapDrawable);