Java 如何在android中创建自定义布局?
我在不止一个视图中重复了容器Java 如何在android中创建自定义布局?,java,android,android-layout,android-fragments,kotlin,Java,Android,Android Layout,Android Fragments,Kotlin,我在不止一个视图中重复了容器 如何只创建一次这个容器,并使用builder设计模式实现它的类 示例:我让TextView查看其颜色,并根据片段更改文本 您好,您的文本视图的通用布局将其命名为layout\u text\u view.xml <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <
如何只创建一次这个容器,并使用builder设计模式实现它的类
示例:我让TextView查看其颜色,并根据片段更改文本 您好,您的文本视图的通用布局将其命名为layout\u text\u view.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="dark"
type="Boolean" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtTitle"
android:text="Some Random Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawablePadding="@dimen/padding_medium"
android:textColor='@{dark?@color/white:@color/colorBlack}'
android:textSize="@dimen/txt_xxxx_large"
app:fontFamily="@font/sfprotext_bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
在build.gradel(应用程序级)中。在android tag中我如何使用builder设计模式来实现这个布局?你能展示一些你想要实现的代码吗?
<include
android:id="@+id/toolbar"
layout="@layout/layout_toolbar"
app:dark='@{true}'
/>
dataBinding {
enabled true
}