【发布时间】:2022-04-06 14:40:21
【问题描述】:
我的项目包含多个模块,而我正在使用的其他模块的aar 文件包含自定义视图和组件。所以我在 .aar 中有一个 XML,我想在我的项目中使用它。
当然可以,但是DataBinding不会在生成的文件中生成,所以我无权访问XML的组件和小部件。
我的片段的 XML 是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Comes from AAR file -->
<include
android:id="@+id/toolbarLayout"
layout="@layout/simple_tool_bar" />
简单的工具栏是:
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/simple_tool_bar_height"
app:elevation="0dp">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:navigationIcon="?attr/homeAsUpIndicator"
app:navigationIconTint="@color/primary" />
</com.google.android.material.appbar.AppBarLayout>
而Databinding生成的文件是:
public abstract class FragmentTestBinding extends ViewDataBinding {
@NonNull
public final View toolbarLayout;
正如您在生成的文件中看到的那样,toolbarLayout 是 View 的一个实例,但它应该是 SimpleToolBarBinding。
当您处理包含模块而不是 .aar 的项目时,一切正常,但在生成 .aar 文件并在另一个项目中使用它之后却不行。
【问题讨论】:
-
你有样例项目让我研究一下吗?
-
我也有同样的问题,有解决办法吗?
-
不确定,您也可以使用
作为 XML 的第一个元素进行测试。那么请在这里分享结果
标签: android data-binding aar android-viewbinding