安卓使用shape时,用代码修改shape颜色属性

例如Shape代码:

<?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)Button.getBackground();
myGrad.setColor(Color.RED);

猜你喜欢

转载自blog.csdn.net/qq_36347817/article/details/81088024
今日推荐