Java 当以编程方式用作背景时,如何更改ImageButton可绘制颜色?
我有以下图像按钮:Java 当以编程方式用作背景时,如何更改ImageButton可绘制颜色?,java,android,android-studio,imageview,android-imagebutton,Java,Android,Android Studio,Imageview,Android Imagebutton,我有以下图像按钮: <ImageButton android:id="@+id/nopeButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/nope_button_states" /> 现在,我想更改可拉丝的色调。当我与一起使用时: android:src="@drawable/no
<ImageButton
android:id="@+id/nopeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/nope_button_states" />
现在,我想更改可拉丝的色调。当我与一起使用时:
android:src="@drawable/nope_button"
然后我可以做:nopeButton.setColorFilter()
,但在后台使用时,这不再有效
与背景属性一起使用时,如何更改ImageButton图形的色调?尝试使用:
nopeButton.getBackground().setColorFilter();
但是输入不仅仅是一个int。我必须使用什么参数才能更改绘图颜色?它不应该更改图像的transaprent部分。请尝试使用setColorFilter(yourcolor,Mode.SRC_);这只起作用一次。当我第一次点击按钮时,它的颜色改变了,但第二次什么也没发生。有什么想法吗?我试着在点击一个按钮的时候调用setColorFilter,背景颜色每次都会以随机颜色正确地改变(我写了一小段代码来尝试)。你能发布你的onClick代码吗?
nopeButton.getBackground().setColorFilter();