gpt4 book ai didi

android - 如何以编程方式更改形状颜色?

转载 作者:太空狗 更新时间:2023-10-29 16:33:28 25 4
gpt4 key购买 nike

<分区>

<?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);

我还没有重构,但这段代码对我有用。谢谢你

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com