Android Studio doesn't generate Drawable from VectorDrawable for old versions -
i use android studio 2.0 , support vectordrawable
library. gradle:
android { compilesdkversion 23 buildtoolsversion "23.0.3" defaultconfig { minsdkversion 8 vectordrawables.usesupportlibrary = true } aaptoptions { additionalparameters "--no-version-vectors" } }
but when try load icon in menu on old device:
menuitem misubjects = menu.add(r.id.menu_navigation, action_subjects_id, order, r.string.action_subjects); misubjects.seticon(contextcompat.getdrawable(this, r.drawable.ic_labels_gray_24dp));
icon vector androidstudio must generate , drawable old versions (raster drawable). if isn't when how need use it?
vector example ic_labels_gray_24dp.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportheight="24.0" android:viewportwidth="24.0"> <path android:fillcolor="#8a000000" android:pathdata="m15.316,4.5 l-10.316,0.008c-1.169,-0 -2,0.96 -2,2v5.984c0,1.043 0.78,2 2,2l10.316,0.008c0.991,0 0.968,0.014 1.543,-0.6l4.141,-4.4 -4.141,-4.4c-0.594,-0.594 -0.552,-0.6 -1.543,-0.6zm20.019,13.459 l18.316,15.269c-0.284,0.303 -0.614,0.743 -1.354,1.027 -0.741,0.285 -1.161,0.203 -1.646,0.203h-0.002l-10.316,-0.008c-0.74,0 -1.413,-0.225 -1.998,-0.578v1.578c0,1.043 0.78,2 2,2l10.316,0.008c0.991,0 0.968,0.014 1.543,-0.6l4.141,-4.4 -0.98,-1.041z"/> </vector>
p.s. wrote simple class. doesn't fix android studio bug @ least app not crash. maybe else has same problem.
public final class vectordrawable { private vectordrawable() {} public static drawable getdrawable(context context, final int id) { return vectordrawablecompat.create(context.getresources(), id, context.gettheme()); } }
Comments
Post a Comment