簡體   English   中英

如何以編程方式更改 android 的值: tint 屬性<bitmap xml< div><div id="text_translate"><p> 我是新來的,我需要你的幫助。 請告訴我如何從程序級別訪問層列表 xml 結構並從程序級別動態更改 bitmap 的“色調”顏色。</p><pre> &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:id="@+id/bg_peper" android:right="65dp"&gt; &lt;bitmap android:gravity="top|left" android:tint="@color/red" android:src="@drawable/ic_favorite" /&gt; &lt;/item&gt; &lt;item.... &lt;/layer-list&gt;</pre></div></bitmap>

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM