There are already many similar questions on SO, like this one, but the answers don't apply (anymore?).
This is how I create the button:
<Button
android:id="@+id/myId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
This is how I change the color:
myButton.getBackground().setColorFilter(lightSalmon, PorterDuff.Mode.SRC);
So far, so good. Now I want to change it back to the default. This is what I tried so far:
myButton.getBackground().clearColorFilter();
makes the button background white instead of the default grey. Same as:
myButton.getBackground().setColorFilter(null);
This completely changes the look of the button:
myButton.setBackgroundResource(android.R.drawable.btn_default);
It does reset the color, but the button looks completely different. Also not what I want.
I found setTint() in the API, but I haven't tried it, because it requires API level 21 (I'm on 15). Is there a backwards compatible way for setTint()?
Trying to remember the default color programmatically doesn't work either, because getColorFilter() also requires API level 21. (setColorFilter()on the other hand was there since API level 1).
Another option I can think of is to just apply the default grey (if I can determine its value). But I fear this might be biased: The default grey might be different on other phones, with other Android versions, other themes and styles...
What other options do I have?