首页 > 解决方案 > 包含布局的android绑定值失败,

问题描述

我尝试设置值以包括布局。我将根布局包装到标记并使用app:headerTitle. 但我得到了这个错误

AAPT: C:\Users\ckdrb\Desktop\EMOPlayer\app\build\intermediates\incremental\mergeDebugResources\stripped.dir\layout\activity_equalizer.xml:11: error: attribute headerTitle (aka com.jakchang.emo:headerTitle) not found.
error: failed linking file resources.

我不明白出了什么问题,因为我遵循了很多例子。

均衡器.xml

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/player_background_theme"
    android:orientation="vertical">
    <include
        android:id="@+id/appbar"
        layout="@layout/layout_part_appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:headerTitle="bas123"/>
</LinearLayout>
</layout> 

layout_part_appbar.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <data>
        <variable
            name="headerTitle"
            type="String" />
    </data>
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/loginHeaderLayout"
        android:layout_width="match_parent"
        android:layout_height="56dp">

        <Button
            android:id="@+id/backButton"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginStart="5dp"
            android:background="@drawable/back_arrow_black"
            app:backgroundTint="@null"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/headerTitleText"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center"
            android:textAlignment="center"
            android:textSize="@dimen/appbar_title_text_size"
            android:textStyle="bold"
            android:textColor="@color/colorBlack"
            android:layout_marginStart="10dp"
            android:text="@{headerTitle}"
            app:layout_constrainedWidth="true"
            app:layout_constraintHorizontal_bias="0"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/backButton"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

标签: android

解决方案


要使用数据绑定传递值,您需要将其设置如下

app:headerTitle="@{`bas123`}"

推荐阅读