Android StateListDrawable可从API级别21以下的svg-s中提取

Android StateListDrawable可从API级别21以下的svg-s中提取,android,svg,android-support-library,android-4.4-kitkat,statelistdrawable,Android,Svg,Android Support Library,Android 4.4 Kitkat,Statelistdrawable,我想在API级别21之前使用可伸缩矢量图形重构我的应用程序(这是可能的,因为支持库23.2是一个很酷的工作人员),而不是生成png-s。 我唯一的问题是,我无法使它与stateListDrawable一起工作。在重构之前,我使用了stateListDrawable,如: <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="fa

我想在API级别21之前使用可伸缩矢量图形重构我的应用程序(这是可能的,因为支持库23.2是一个很酷的工作人员),而不是生成png-s。 我唯一的问题是,我无法使它与stateListDrawable一起工作。在重构之前,我使用了stateListDrawable,如:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:drawable="@drawable/dashboard_reset_max_alt_disabled" />
    <item android:state_pressed="true" android:drawable="@drawable/dashboard_reset_max_alt_pressed"/>
    <item android:drawable="@drawable/dashboard_reset_max_alt"/>
</selector>
getDrawable方法如下所示:

Drawable d;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    d = c.getDrawable(resId);
else d = c.getResources().getDrawable(resId);
// Wrap the drawable so that future tinting calls work
// on pre-v21 devices. Always use the returned drawable.
return DrawableCompat.wrap(d);
我知道我可以通过编程方式创建StateListDrawables,但是我更喜欢一种变通方法,这样我就可以使用我已经使用过的xml-s。你有什么想法吗

Drawable d;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    d = c.getDrawable(resId);
else d = c.getResources().getDrawable(resId);
// Wrap the drawable so that future tinting calls work
// on pre-v21 devices. Always use the returned drawable.
return DrawableCompat.wrap(d);