首页 > 解决方案 > 将属性从包含的布局传递给布局时出错

问题描述

为了使我的应用程序代码更清晰,我尝试创建通用 xml,但出现如下错误:

error: activity_login.xml:230: AAPT: error: attribute buttonTitle

在我的 Login.xml 文件中:

 <include
        android:id="@+id/login_button"
        layout="@layout/widget_large_button"
        app:buttonTitle="@string/login"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"/>

我已经定义了如下布局:

<data>
    <variable
        name="buttonTitle"
        type="String"/>
</data>

<androidx.appcompat.widget.AppCompatButton
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="25dp"
    android:layout_marginEnd="25dp"
    android:layout_marginBottom="16dp"
    android:background="@drawable/stripe_backgound_05"
    android:clickable="false"
    android:focusable="false"
    android:letterSpacing="0.5"
    android:paddingTop="25dp"
    android:paddingBottom="25dp"
    android:text="@{buttonTitle}"
    android:textAllCaps="true"
    android:textColor="@color/gainsboro_05"
    android:textSize="16sp"/>

看来我无法将 login.xml 中的 buttonTitle 传递给按钮小部件。

任何想法?

谢谢

标签: androidkotlinandroid-layoutlayoutandroid-include

解决方案


尝试添加bind:buttonTitle="@{'variable name of login.xml'}" 包含标签


推荐阅读