Android 如何在兼容模式下使用可绘制向量的着色?

Android 如何在兼容模式下使用可绘制向量的着色?,android,android-appcompat,android-vectordrawable,Android,Android Appcompat,Android Vectordrawable,我正在尝试为使用vector drawable的ImageButton应用色调: <android.support.v7.widget.AppCompatImageButton android:id="@+id/flashlight_button" app:srcCompat="@drawable/ic_flash_off_black_24dp" android:tint="@color/icon_states_color"

我正在尝试为使用vector drawable的ImageButton应用色调:

<android.support.v7.widget.AppCompatImageButton
           android:id="@+id/flashlight_button"
           app:srcCompat="@drawable/ic_flash_off_black_24dp"
           android:tint="@color/icon_states_color"
           />

这将工作棒棒糖+,但会崩溃Kitkat


如何在应用程序compat world中为Kitkat设置颜色列表着色?

您好,您可以通过编程在图像按钮中添加着色,并检查它是否位于棒棒糖下方,然后在aternate方式下方工作

根据本文,android:backgroundTint的相关方法是

更新

按照此步骤了解如何创建颜色状态列表资源

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:color="#your_color_here" />
</selector>
其中
contextInstance
上下文的实例


使用AppCompart

btnTag.setSupportButtonTintList(ContextCompat.getColorStateList(Activity.this, R.color.colorPrimary));
试着这样做,希望这能对你有所帮助。

你能做到

但是不能对颜色(…lame)使用@color引用,否则它将只对L有效+

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
<path
    android:fillColor="#FFAABB"
    android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zm-6,0C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>


android:矢量中的色调可通过工作绘制。所以只有android:tint在布局中应该避免。

愚蠢的引用,它不能与它们一起工作。浪费了很多时间。非常感谢。
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
<path
    android:fillColor="#FFAABB"
    android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zm-6,0C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>