我是新来的,需要你的帮助。请告诉我如何从程序级访问layer-list xml结构,以及如何从程序级动态改变位图的"tint“颜色。
<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>
发布于 2021-05-08 04:40:31
使用此命令动态更改色调
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
https://stackoverflow.com/questions/67440827
复制相似问题