如何解决如何以编程方式更改 <bitmap xml 中的 android: tint 属性的值
我是新来的,我需要你的帮助。请告诉我如何从程序级别访问layer-list xml结构并从程序级别动态更改位图的“色调”颜色。
<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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。