[英]How to programmatically change the value of the android: tint property in <bitmap xml
我是新来的,我需要你的帮助。 请告诉我如何从程序级别访问层列表 xml 结构并从程序级别动态更改 bitmap 的“色调”颜色。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/bg_peper" android:right="65dp">
<bitmap
android:gravity="top|left"
android:tint="@color/red"
android:src="@drawable/ic_favorite" />
</item>
<item....
</layer-list>
使用此动态更改色调
ImageView view = (ImageView)findViewById(R.id.tintLayerView); // ImageView where you have added the drawable as src
LayerDrawable layerDrawable = (LayerDrawable)view.getDrawable();
Drawable bpPeperDrawable = layerDrawable.findDrawableByLayerId(R.id.bg_peper);
DrawableCompat.setTint(bpPeperDrawable.mutate(), ContextCompat.getColor(this, R.color.red)); // Use the required color here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.