答案 0 :(得分:2)
您可以扩展目标Drawable
类(可能是ColorDrawable
)。然后在Path
方法中绘制一个梯形draw(Canvas)
。调整Paint
的alpha和颜色以更改效果。代码可能如下:
public class SDrawable extends ColorDrawable {
private Path mPath = new Path();
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
public SDrawable() {
init();
}
public SDrawable(int color) {
super(color);
init();
}
private void init(){
mPaint.setColor(0x33ffffff);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
mPath.reset();
mPath.moveTo(0,0);
mPath.lineTo(canvas.getWidth()/2+50, 0);
mPath.lineTo(canvas.getWidth()/2, canvas.getHeight());
mPath.lineTo(0, canvas.getHeight());
mPath.lineTo(0, 0);
canvas.drawPath(mPath, mPaint);
}
}
答案 1 :(得分:0)
在布局背景下使用drawable
XML下方,根据应用需要更改drawable
XML下面的颜色。
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:startColor="@color/application_background"
android:endColor="@color/bright_red"
android:angle="45"/>
</shape>
</item>
</selector>
请参阅以下链接,了解如何更改和使用上述代码。