我有一个主活动,并在操作栏中指定了侧边导航抽屉,如下所示(请注意,为了简洁起见,省略了大量代码)在default_screen.xml中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="190dp"
android:background="@drawable/honeycomb"
android:orientation="vertical"
>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="@layout/header"
app:menu="@menu/drawer"
/>
布局/头部如下所示(出于简洁起见,省略了很多行):
<data>
<variable name="user" type="oose2017.place2b.ClientUser"/>
</data>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.displayName}"
android:textSize="14sp"
android:textColor="#FFF"
android:textStyle="bold"
android:gravity="left"
android:paddingBottom="4dp"
android:id="@+id/username"
android:layout_above="@+id/email"
android:layout_alignLeft="@+id/profile_image"
android:layout_alignStart="@+id/profile_image" />
</RelativeLayout>
我在主活动中实例化我的默认屏幕,如下所示:
setContentView(R.layout.default_screen);
如何将数据绑定到标题?我尝试了几个不成功的方法,主要包括:
DefaultScreenBinding binding = DataBindingUtil.setContentView(R.layout.default_screen);
哪种方法不起作用。我该怎么做?