gpt4 book ai didi

java - 以编程方式用作背景时如何更改 ImageButton 可绘制颜色?

转载 作者:行者123 更新时间:2023-11-30 10:57:34 26 4
gpt4 key购买 nike

我有以下 ImageButton:

<ImageButton
android:id="@+id/nopeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/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>

现在我想更改可绘制对象的色调。当我使用时:

android:src="@drawable/nope_button"

然后我可以这样做:nopeButton.setColorFilter() 但是在后台使用时这不再有效。

如何在与背景属性一起使用时更改 ImageButton 绘图的色调?

最佳答案

尝试使用:

nopeButton.getBackground().setColorFilter();

关于java - 以编程方式用作背景时如何更改 ImageButton 可绘制颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32569695/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com