[英]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.