appWidget 모양의 색상을 변경하려고합니다. 모서리가있는 사각형이 있으며, 목표는 배경색 (단색)과 테두리 색을 변경하는 것입니다.appWidget에서 모양 변경
내 위젯 레이아웃이 이미지 뷰의 src 속성은이 모양 배경에 대한 이미지 뷰와 RelativeLayout의입니다:
여기<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners
android:radius="5dp"
android:topRightRadius="5dp"
android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp" />
<stroke
android:width="1dp"
android:color="@android:color/white" />
<solid android:color="@color/transparent"/>
</shape>
내가 배경을 변경하려고 할 때 내가 할 노력하고있어입니다 색상 :
RoundRectShape sd = new RoundRectShape(new float[]{30,30,30,30,30,30,30,30}, null, null);
bmp_bg = Bitmap.createBitmap(200, 20, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmp_bg);
Paint p = new Paint();
p.setColor(0xFF0000FF);
sd.draw(c, p);
remoteViews.setImageViewBitmap(R.id.imageClock, bmp_bg);
하지만 배경은 변경되지 않습니다. 이것이 좋은 방법인가요? 아니면 completly 틀린거야? 들으
편집 : 클래스 CustomShapeClockWidget의 존재와
CustomShapeClockWidget cscw = new CustomShapeClockWidget(0xFF0000FF, 0xFFFF0000);
bmp_bg = Bitmap.createBitmap(200, 20, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmp_bg);
cscw.draw(c);
remoteViews.setImageViewBitmap(R.id.imageClock, bmp_bg);
: 나도 아무런 영향없이이 시도
public class CustomShapeClockWidget extends ShapeDrawable {
private int bgColor, strokeColor;
private Paint fillPaint, strokePaint;
public CustomShapeClockWidget(int bgColor, int strokeColor){
this.bgColor = bgColor;
this.strokeColor = strokeColor;
}
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint){
fillPaint = this.getPaint();
strokePaint = new Paint(fillPaint);
fillPaint.setColor(bgColor);
strokePaint.setStyle(Paint.Style.STROKE);
strokePaint.setStrokeWidth(1.0f);
strokePaint.setColor(strokeColor);
shape.draw(canvas, fillPaint);
shape.draw(canvas, strokePaint);
}
}
(아주 늦은 의견이지만) remoteViews.setImageViewBitmap을 호출 한 후 appwidget을 업데이트하고 있습니까? –