0
我和讓我插件使自己顯得漂亮掙扎,但小部件還擊;(設置小部件背景漸變
我有一個小部件佈局背景設置爲產生線性漸變問題
現在,我已經找到了如何生成的顏色是漸變定製「weigth」線性漸變:
public static PaintDrawable createLinearGradient(final int left, final int top, final int right, final int bottom,
final int[] colors, final float[] positions)
{
ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory()
{
@Override
public Shader resize(int width, int height)
{
LinearGradient lg = new LinearGradient(left, top, right, bottom, colors, positions, Shader.TileMode.REPEAT);
return lg;
}
};
PaintDrawable gradient = new PaintDrawable();
gradient.setShape(new RectShape());
gradient.setShaderFactory(shaderFactory);
return gradient;
}
這裏是設置控件背景繪製從文件夾中繪製的方式:
int backgroundId = getDrawableByName(context, "round_transparrent_background");
remoteViews.setInt(R.id.mainLayout, "setBackgroundResource", backgroundId);
我需要一種方法來寫該命令如下:
Drawable background = createLinearGradient(params ...);
remoteViews.setInt(R.id.mainLayout, "setBackgroundResource", background);