Zuerst Ihre Bestellung von Array ist falsch. Standardwert muss der letzte Zustand sein, so benutzen Sie diese ein:
mButtonBold.setSupportBackgroundTintList(new ColorStateList(
new int[][]{PRESSED_ENABLED_STATE_SET,EMPTY_STATE_SET},
new int[]{Color.GREEN,Color.BLUE}
))
XML
<android.support.v7.widget.AppCompatImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_done"
app:backgroundTint="@drawable/background"
app:backgroundTintMode="src_over"/>
ziehbar/Hintergrund
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorAccent" android:state_pressed="true" />
<item android:color="@color/colorPrimary" />
</selector>
JAVA
, wenn man bedenkt, das Layout ist so etwas wie dieses:
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_done" />
dann:
AppCompatImageButton imageButton = (AppCompatImageButton)findViewById(R.id.imageButton);
imageButton.setSupportBackgroundTintList(new ColorStateList(
new int[][]{new int[]{android.R.attr.state_pressed},
new int[]{}
},
new int[]{Color.GREEN,Color.BLUE}
));
imageButton.setSupportBackgroundTintMode(PorterDuff.Mode.SRC_OVER);
, wenn Sie SDK Widget verwenden android
Präfix statt app
wo
xmlns:app="http://schemas.android.com/apk/res-auto"
verwenden werden und
xmlns:android="http://schemas.android.com/apk/res/android"
was sind diese Konstanten '{EMPTY_STATE_SET, PRESSED_ENABLED_STATE_SET}'? tint' Veränderung Bildfarbe durch die Schaffung eines Filters darauf: –
Diese Konstanten wurden in android 'View' Klasse –