android中图形颜色的编程更改

android中图形颜色的编程更改,android,android-button,android-drawable,android-shape,Android,Android Button,Android Drawable,Android Shape,我试图以编程方式更改中形状的颜色,但它不起作用 这是形状 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#9F2200"/> <stroke android:width="2dp"

我试图以编程方式更改中形状的颜色,但它不起作用

这是形状

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#9F2200"/>
    <stroke android:width="2dp" android:color="#fff" />
</shape>

但当我改变背景颜色时,它会从屏幕上删除按钮。

如下更改代码

GradientDrawable bgShape = (GradientDrawable)btn_ColorPick.getBackground();
 bgShape.mutate()
 bgShape.setColor(Color.RED);

@德尔格伦:我也问了同样的问题,但对我来说没用。太棒了,非常感谢!
GradientDrawable bgShape = (GradientDrawable)btn_ColorPick.getBackground();
bgShape.setColor(Color.RED);
GradientDrawable bgShape = (GradientDrawable)btn_ColorPick.getBackground();
 bgShape.mutate()
 bgShape.setColor(Color.RED);