包含布局的视图绑定不起作用

RedSight:

我想使用视图绑定在包含布局中绑定视图。我给了包含id为“ topBar”的布局,但仍然无法访问其中的视图。我尝试使用Android Studio自动修复功能创建一个局部变量以查看其类型。它显示类型“ android.widget.a”,我正在使用Android Studio4.0。这是Android Studio中的错误吗?

我的活动

    private ActivityWalletBinding viewBinding;
    private ViewTitleBinding topBarBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewBinding = ActivityWalletBinding.inflate(getLayoutInflater());
        setContentView(viewBinding.getRoot());
        viewBinding.topBar;
        android.widget . a = viewBinding.topBar; //Create local var using auto fix in android 
studio 
}

activity_wallet.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <include
        android:id="@+id/topBar"
        layout="@layout/view_title"/>

view_title.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="65dp"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/white"
    android:paddingTop="19dp"
    android:id="@+id/fl_tab">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <ImageView
            android:id="@+id/btn_back"
            android:layout_width="39dp"
            android:layout_height="39dp"
            android:layout_centerVertical="true"
            android:onClick="backClick"
            android:padding="11dp"
            android:src="@mipmap/icon_back"
            android:tint="@color/gray1"
            />
        <TextView
            android:id="@+id/titleView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:textColor="@color/textColor"
            android:textSize="18sp"
            android:textStyle="bold"
            />
        <TextView
            android:id="@+id/tv_right_title"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:layout_alignParentRight="true"
            android:layout_marginRight="11dp"
            android:textColor="@color/enable_right_title"
            android:textSize="15sp"
            tools:text="假文字"
            />
    </RelativeLayout>
</FrameLayout>

这是Android Studio的错误还是什么?

RedSight:

我对此没有任何反应,它会自动运行。我确实确实清理过,重建过,重新启动过Android Studio……当时确实有些事情,但是无法正常工作。也许在另一个类中链接另一个布局会触发某些问题,只是将其修复即可,因为我搁置了这个问题并继续进行下去。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章