[英]Android include layout: pass Drawable parameter using data binding gives error: AAPT: error: attribute mysrc (aka com.example.APPNAME:mysrc) not found
I am trying to pass a Drawable
as parameter into my include
.我正在尝试将Drawable
作为参数传递到我include
中。
I have enabled dataBinding in my build.gradle
file:我在build.gradle
文件中启用了 dataBinding:
android {
dataBinding {
enabled = true
}
....
}
action_bar_button.xml: 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: 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
:这一直让我错误指向我的activity_main.xml
中的include
语句:
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:如果我将activity_main.xml
中的app:mysrc
更改为android:mysrc
,它会给我错误:
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.我已经坚持了几个小时,并且尝试了很多 Stack Overflow 帖子,但似乎无法解决它。
Here, there must be a drawable variable in both the action_bar_button.xml and activity_main.xml layout files这里,action_bar_button.xml和activity_main.xml布局文件中都必须有一个drawable变量
I assume you should have this in your included layout:我假设您应该在包含的布局中包含此内容:
<data>
<variable name="mysrc" type="android.graphics.drawable.Drawable"/>
</data>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.