首先來一個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);