Android 怎麼動態設置shape定義的控件的背景色

首先來一個shape的xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval"
    android:useLevel="false">
    <solid
        android:color="#ff0" /> 
    <size android:width="36dp"
        android:height="36dp" /> 
</shape>


在代碼中可以設置如下:

GradientDrawable p = (GradientDrawable) textview.getBackground();
p.setColor(Color.RED);


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章