我在 xml
中定义了一个 Shape
。现在我需要从代码中更改一个 solid color
,请问如何操作?
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#000000"/>
<corners
android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp"/>
</shape>
最佳答案
我在我的代码中使用它
GradientDrawable myGrad = (GradientDrawable)rectangle.getBackground();
myGrad.setColor(Color.BLACK);
希望这有帮助:)
编辑:GradientDrawable
而不是 ShapeDrawable
关于android - 如何从代码中更改 `solid color`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16775891/