Android Selector Drawable with VectorDrawables srcCompat

后端 未结 5 1113
轻奢々
轻奢々 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:04

    I suggest this workaround to make the color change based on state: Set a normal, white VectorDrawable, and have the tint have the color selector.

    This was tested to work even on emulator with Android API 16, and it works even if you set "vectorDrawables.useSupportLibrary = true" in gradle, of course.

    Example: first view is enabled, and the second is disabled:

    MainActivity.kt

    class MainActivity : AppCompatActivity() {
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
            disabledSendMessageButton.isEnabled = false
        }
    }
    

    res/layout/activity_main.xml

    
    
        
    
        
    
    

    res/color/color_selector.xml

    
        
        
    
    

    res/drawable/ic_baseline_send_24.xml

    
        
    
    

提交回复
热议问题