动态更改xml drawables颜色

时间:2015-05-26 06:59:26

标签: android

我在drawable文件夹中有一个xml形状

<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">

    <corners android:radius="0dp" />
    <solid android:color="@color/very_light_gray" />
    <stroke
        android:width="1dip"
        android:color="@color/dark_gray" />
</shape>

如何以编程方式更改very_light_graydark_gray颜色? 有什么办法吗? 这是否可以覆盖形状类并使用覆盖的类而不是xml中的形状?

1 个答案:

答案 0 :(得分:1)

您可以修改它。

GradientDrawable bgShape = (GradientDrawable)yourView.getBackground();
bgShape.setColor(Color.WHITE);