【发布时间】:2015-12-08 10:20:45
【问题描述】:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="@dimen/radius_default"/>
<solid
android:color="@color/alpha"/>
<stroke
android:width="1dp"
android:color="@color/red"/>
</shape>
我想在运行时改变描边的颜色。
我使用了这段代码,但它不起作用。
Drawable drawable = getResources().getDrawable(R.drawable.border_red);
drawable.setColorFilter(Color.BLUE), PorterDuff.Mode.SRC_ATOP);
container.setBackground(drawable);
如何改变笔画的颜色?
float[] outerR = new float[] { 12, 12, 12, 12, 0, 0, 0, 0 };
RectF inset = new RectF(6, 6, 6, 6);
float[] innerR = new float[] { 12, 12, 0, 0, 12, 12, 0, 0 };
ShapeDrawable biggerCircle = new ShapeDrawable(new RoundRectShape(outerR,inset, innerR));
biggerCircle.setIntrinsicHeight( 60 );
biggerCircle.setIntrinsicWidth( 60);
biggerCircle.setBounds(new Rect(30, 30, 30, 30));
biggerCircle.getPaint().setColor(Color.BLUE);
border.setBackgroundDrawable(biggerCircle);
我还没有重构,但这段代码对我有用。谢谢你
【问题讨论】:
-
@Lakhan 谢谢! ^^
-
@jihoonkim 很高兴它成功了
标签: android