我按照一些例子画了一个圆圈,但是当我改变颜色时,圆圈变成了一个正方形。颜色应用于视图。如何更改具有“@+id/circle2”颜色的实际圆圈,而不是包含该圆圈的投射视图。
圈子.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"
android:id="@+id/circle2" > >
<gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF"
android:angle="270"/>
</shape>
这是在主 xml
<View
android:id="@+id/colordot"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="325dp"
android:layout_marginTop="35dp"
android:background="@drawable/circle" />
我投射了包含 circle.xml 的视图
F1Color =(View) findViewById(R.id.colordot);
我改变颜色
F1Color.setBackgroundColor(Color.rgb(R_value,G_value,B_value));
这个很好用,谢谢
private void SetColorDot(int index, int i, int j, int k)
Resources res = getResources();
final Drawable drawable = res.getDrawable(R.drawable.circle);
drawable.setColorFilter(Color.rgb(i, j, k), Mode.SRC_ATOP);
ImageView img = (ImageView) findViewById(R.id.colordot1);
img.setBackgroundDrawable(drawable);