非常疯狂的问题:
我正在尝试更改设置为 ConstraintLayout
背景的 Nine-Patch 的颜色。 XML 中的 android:backgroundTint
工作正常,但这仅受 Android 5.0+ 支持。使用 app:backgroundTint
而不是 android:backgroundTint
不会改变颜色。
我的 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>
有人知道另一种改变颜色的方法吗? 感谢任何帮助。
最佳答案
我刚找到答案:
在 onCreate()
方法中:
View line = findViewById(R.id.line);
ColorStateList tint = ColorStateList.valueOf(ContextCompat.getColor(this, android.R.color.holo_blue_light));
ViewCompat.setBackgroundTintList(line, tint);
感谢@azizbekian 的建议。
关于android - 更改设置为 ConstraintLayout 背景的 Nine-Patch 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47004857/