Android Selector Drawable with VectorDrawables srcCompat

后端 未结 5 1111
轻奢々
轻奢々 2020-12-04 08:50

I\'m facing a problem with the new backward compatibility with VectorDrawables. In the Support Library 23.2 was a new feature for backward compatibility with Android VectorD

5条回答
  •  悲哀的现实
    2020-12-04 09:11

    As @Jahnold mentioned in the comment to question, support for loading vector drawable from an xml state xml list was removed in 23.3.

    However, I found several approaches that can help.

    1. Using Tint

    The approach is suitable if the drawables from selected state list difference only by colors.

    First, create only one vector drawable with tint and white fillColor:

    
    
    
        
    
        
    
    
    

    Second, create color state list button_tint.xml placed in res/color

    
    
        
        
    
    

    Don't forget add follow lines to build.gradle or the approach will not work on old Android versions.

    defaultConfig {
        vectorDrawables.useSupportLibrary = true
    }
    

    2. Hardcode creating StateListDrawable

    The approach is suitable if you use for the state list vector drawables which difference not only a color but also by a figure so you need create several different xml files. Then you can create StateListDrawable programmatically as shown in an answer.

提交回复
热议问题