我有一个像这样的 LinearLayout:
<LinearLayout
android:background="@drawable/circle"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:id="@+id/powerCircle"
android:layout_width="20dp"
android:layout_height="20sp" />
然后我有一个彩色圆圈的背景,像这样:
圆.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666666"/>
<size
android:width="20dp"
android:height="20dp"/>
</shape>
在我的自定义适配器
中,我想根据状态变量更改圆圈的背景颜色。
如何获取对圆圈
背景的引用?
最佳答案
也许,这样的事情应该可行:
GradientDrawable background = (GradientDrawable) linearView.getBackground();
background.setColor(getResources().getColor(R.color.some_color));
关于android - 在 LinearLayout 中更改圆圈的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29437289/