I am trying to pass a Drawable as parameter into my include.
I have enabled dataBinding in my build.gradle file:
android {
dataBinding {
enabled = true
}
....
}
action_bar_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="mysrc" type="android.graphics.drawable.Drawable"/>
</data>
<ImageButton android:id="@+id/notification"
android:background="@null"
android:foreground="?android:attr/actionBarItemBackground"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:padding="15dp"
android:src="@{mysrc}"
android:scaleType="fitCenter"></ImageButton>
</layout>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity"
android:id="@+id/mainlayout">
<include layout="@layout/action_bar_button" app:mysrc="@{@drawable/notification}"/>
</RelativeLayout>
This keeps giving me error pointing to the include statement in my activity_main.xml:
AAPT: error: attribute mysrc (aka com.example.APPNAME:mysrc) not found.
If I change the app:mysrc in activity_main.xml to android:mysrc, it gives me error:
AAPT: error: attribute android:mysrc not found.
I have been stuck with this for few hours and have tried quite a few Stack Overflow posts but can't seem to resolve it.
Here, there must be a drawable variable in both the action_bar_button.xml and activity_main.xml layout files
I assume you should have this in your included layout:
<data>
<variable name="mysrc" type="android.graphics.drawable.Drawable"/>
</data>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With