I'm trying to change the color of a Nine-Patch that's set as the background of a ConstraintLayout
. android:backgroundTint
in the XML works fine, but this is only supported by Android 5.0+. Using app:backgroundTint
instead of android:backgroundTint
doesn't change the color.
My XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="29dp"
android:background="@drawable/round"
android:backgroundTint="@android:color/darker_gray">
</android.support.constraint.ConstraintLayout>
Does anyone know another way to change the color? Any help is appreciated.
I've just found the answer:
in the onCreate()
method:
View line = findViewById(R.id.line);
ColorStateList tint = ColorStateList.valueOf(ContextCompat.getColor(this, android.R.color.holo_blue_light));
ViewCompat.setBackgroundTintList(line, tint);
Thanks to @azizbekian for the suggestion.