繁体   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