简体   繁体   English

Android 包括布局:使用数据绑定传递可绘制参数给出错误:AAPT:错误:找不到属性 mysrc(又名 com.example.APPNAME:mysrc)

[英]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.

相关问题 AAPT:错误:找不到属性 buttonColor(又名 com.example.*appName*) - AAPT: error: attribute buttonColor (aka com.example.*appName*) not found Android 错误:AAPT:错误:找不到资源 drawable/ic_bot(又名 com.example.chatbot:drawable/ic_bot) - Android error: AAPT: error: resource drawable/ic_bot (aka com.example.chatbot:drawable/ic_bot) not found 如何修复 AAPT:错误:找不到资源 drawable/tt(又名 com.example.polyresults:drawable/tt) - How to fix AAPT: error: resource drawable/tt (aka com.example.polyresults:drawable/tt) not found 我无法解决错误:找不到资源可绘制/ abc(又名com.example.myapplication:drawable / abc) - I cant solve error:resource drawable/abc (aka com.example.myapplication:drawable/abc) not found AAPT:错误:属性 android:clipToOutline 未找到 - AAPT: error: attribute android:clipToOutline not found AAPT:错误:找不到属性 startIconDrawable - AAPT: error: attribute startIconDrawable not found Android Studio - 错误:找不到资源可绘制/abc_ic_ab_back_mtrl_am_alpha(又名 com.instacoin:drawable/abc_ic_ab_back_mtrl_am_alpha) - Android Studio - Error:resource drawable/abc_ic_ab_back_mtrl_am_alpha (aka com.instacoin:drawable/abc_ic_ab_back_mtrl_am_alpha) not found AAPT:错误:属性 android:margin_Bottom 未找到 - AAPT: error: attribute android:margin_Bottom not found AAPT:错误:未找到样式属性“android:attr/windowSplashScreenBackground” - AAPT: error: style attribute 'android:attr/windowSplashScreenBackground' not found AAPT:错误:找不到资源样式/Theme.TheDoist.PopupOverlay(又名 com.bawp.todoister:style/Theme.TheDoist.PopupOverlay) - AAPT: error: resource style/Theme.TheDoist.PopupOverlay (aka com.bawp.todoister:style/Theme.TheDoist.PopupOverlay) not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM