我有一个扩展 TextView 的自定义视图,背景是可绘制的,
<CustomView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/circile_background" />
并想在自定义视图中更改背景颜色
public class CustomView extends TextView {
TypedArray typedArray;
public CustomView (Context context) {
super(context);
}
public CustomView (Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setColorLevel(int color) {
// update color here
}
}
在此处检查类似的问题如何在 Android 中更改 Drawable 的颜色?
public void setDangerLevel(int color) {
Drawable drawable=this.getBackground().getCurrent();
drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句