Invalid drawable tag vector

后端 未结 14 962
小蘑菇
小蘑菇 2020-12-28 12:34

Im trying to use vector drawables on pre lollipop devices. I did all as instructed here but i still get this crash.

build.gradle:

14条回答
  •  一生所求
    2020-12-28 13:05

    I'm surprised that this is not mentioned here yet.

    This crash happens often with:

    android:drawableRight
    android:drawableLeft
    android:drawableTop
    android:drawableBottom
    android:drawableStart
    android:drawableEnd
    

    A common fix is to create another drawable that wraps the drawable with , or to set the compound drawable using code, but nowadays you can instead use:

    app:drawableRightCompat
    app:drawableLeftCompat
    app:drawableTopCompat
    app:drawableBottomCompat
    app:drawableStartCompat
    app:drawableEndCompat
    

    This was added to AppCompatTextView in appcompat 1.1.0-alpha01.

    To use the attribute I've had to use AppCompat views instead of usual ones, eg. I've used AppCompatButton instead of Button.


    Not sure if you set vectorDrawables.useSupportLibrary true and AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) (I have both). Check this article from Nick Butcher: https://medium.com/androiddevelopers/using-vector-assets-in-android-apps-4318fd662eb9.

提交回复
热议问题