2016-06-10 51 views
3

我的应用程序在API < v21下,所以我使用Android支持库23.2来管理我的vectorDrawables。如何使用vectorDrawable作为使用Android支持库23.2的推送通知的图标? setSmallIcon给出错误

android { 
    defaultConfig { 
    vectorDrawables.useSupportLibrary = true 
    } 
} 

所有视图工作正常exept图标推送通知:

NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(this) 
         .setColor(getResources().getColor(R.color.colorAccent)) 
         .setSmallIcon(R.drawable.ic_play_arrow_white_24dp) //ERROR 
         .setContentTitle(getString(R.string.app_name)) 
         .setContentText(getString(R.string.playing)); 

我已经得到了错误:

E/AndroidRuntime: FATAL EXCEPTION: main 
android.app.RemoteServiceException: Bad notification posted from package com.ashomok.lullabies: Couldn't create icon: StatusBarIcon(pkg=com.ashomok.lullabiesuser=0 id=0x7f020053 level=0 visible=true num=0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1401) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5041) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
at dalvik.system.NativeStart.main(Native Method) 

如何使用vectorDrawable在这种情况下?它有可能吗?

+1

像@ianhanniballake说的,在这种情况下你不能使用vectorDrawables。但由于该图标仅用于通知,因此您可以在项目中添加一个小的png,它只需要多几个字节。 –

回答

10

不,VectorDrawables只能在Android 5.0及更高版本的设备上发送到应用程序之外 - 在此之前,框架不知道如何处理矢量绘图。

相关问题