【发布时间】:2021-11-21 02:28:25
【问题描述】:
为了让我的应用程序代码更简洁,我尝试创建通用 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 传递给按钮小部件。
有什么想法吗?
谢谢
【问题讨论】:
-
你可以尝试将变量类型从 String 更改为 CharSequence。
-
它仍然无法正常工作。它不是来自类型。它真的来自 2 布局之间的链接
-
你能传递这样的字符串吗:app:buttonTitle="@{@string/login}"
标签: android kotlin android-layout layout android-include