[英]How to change ImageButton drawable color when used as background programmatically?
I have the following ImageButton:我有以下 ImageButton:
<ImageButton
android:id="@+id/nopeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/nope_button_states" />
Here is nope_button_states
:这是nope_button_states
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="false"
android:drawable="@drawable/nope_button" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/nope_button_selected" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/nope_button_selected" />
<item
android:state_enabled="true"
android:drawable="@drawable/nope_button" />
</selector>
Now I want to change the tint color of the drawable.现在我想更改可绘制对象的色调。 When I use with:当我使用:
android:src="@drawable/nope_button"
then I can do: nopeButton.setColorFilter()
but this does not work anymore when using in background.那么我可以这样做: nopeButton.setColorFilter()
但这在后台使用时不再起作用。
How do I change the tint color from the ImageButton drawings when used with background property?与背景属性一起使用时,如何更改 ImageButton 绘图中的色调颜色?
尝试使用:
nopeButton.getBackground().setColorFilter();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.