When using Android Studio 4.1, the problem of incomplete display of control references in viewBinding

question

When using Android Studio 4.1, if comments are added between UI controls in the layout, and the comments contain "&" characters, viewBinding cannot recognize all controls after the comments:

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

    <TextView
        android:id="@+id/tvTest1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <!-- & -->

    <TextView
        android:id="@+id/tvTest2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

insert image description here

Solution

  • Solution 1: Remove the "&" character.
  • Solution 2: Upgrade Android Studio (tested with Android Studio 4.2 Beta 6 version, there is no related problem).

Guess you like

Origin blog.csdn.net/hanshiying007/article/details/114868319