2016-09-18 27 views
0

我想申请色调为使用矢量绘制的ImageButton:如何在兼容模式下使用tint绘制矢量图?

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

这将工作棒棒堂+,但会崩溃的奇巧。

在应用程序的世界里,ColorList应该如何为Kitkat着色?

回答

0

嗨,你可以以编程方式添加色调在你的图像按钮,并检查它是否低于棒棒糖,然后它工作在以下方式。

按照documentation相关方法android:backgroundTintsetBackgroundTintList(ColorStateList list)

更新

按照此link知道如何创建一个颜色列表资源。

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item 
     android:color="#your_color_here" /> 
</selector> 

然后使用

setBackgroundTintList(contextInstance.getResources().getColorStateList(R.color.your_xml_name)); 

其中contextInstance是使用AppCompart

btnTag.setSupportButtonTintList(ContextCompat.getColorStateList(Activity.this, R.color.colorPrimary)); 

尝试这个瓦特一个的Context


实例加载它唉,希望这会帮助你。

1

你可以做到。

,但你不能使用@color引用的颜色(..lame),否则将只能用于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"/> 

check this link

+0

愚蠢的引用,它不与他们合作。浪费了一堆时间。谢谢 ! – AndreiBogdan

0

安卓与工作矢量绘制内的色调。所以只需要避免android:tint在布局中。