Data Binding with srcCompat

You can simply use android:src attribute instead compat attribute when you set vector resource by DataBinding.

DataBinding library generates class that execute setImageResource method at runtime.

<ImageView
        ...
        android:src="https://stackoverflow.com/questions/35766898/@{@drawable/your_drawable}"
/>

According to http://android-developers.blogspot.com/2016/02/android-support-library-232.html setImageResource method can be used at runtime on older system versions without any additional changes.

If you would like to use app:srcCompat attribute. You must define @BindingMethods annotation which connects attribute with appropriate setter from ImageView. For example in your Activity or Fragment add.

@BindingMethods({
    @BindingMethod(type = android.widget.ImageView.class,
            attribute = "app:srcCompat",
            method = "setImageDrawable") })
public class MainActivity extends AppCompatActivity {
   // your activity body here

}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)