我由于浮动按钮而收到错误消息

时间:2019-01-31 09:52:53

标签: android xml android-layout data-binding floating-action-button

在我的代码中,我正在XML文件中使用数据绑定,并且由于XML中的浮动按钮而遇到错误:

<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
    <import type="android.view.View" />
    <variable
        name="userViewModel"
        type="com.example.projectdatabinding.viewModel.UserViewModel" />
</data>

   <android.support.v4.widget.DrawerLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorWhite"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">


            <ProgressBar
                android:id="@+id/progress_bar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:visibility="@{userViewModel.progressBar}" />

            <TextView
                android:id="@+id/label_status"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@{userViewModel.messageLabel}"
                app:visibility="@{userViewModel.userLabel}" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/list_user"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/colorWhite"
                android:clipToPadding="false"
                android:scrollbars="vertical"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                app:visibility="@{userViewModel.userRecycler}"
                tools:listitem="@layout/item_user" />

        </LinearLayout>
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/fab_margin"
            android:clickable="true"
            android:onClick="@{userViewModel::onClickFabToLoad}"
            android:src="@drawable/ic_account_circle_24dp" />

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.AppBarLayout>

    </android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true" />

</android.support.v4.widget.DrawerLayout>

在logcat中,我得到这样的错误:

Binary XML file line #59: Binary XML file line #59: Error inflating class android.support.design.widget.FloatingActionButton

我的gradle文件是:

 implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.google.code.gson:gson:2.7'

implementation 'com.squareup.retrofit2:retrofit:2.2.0'
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.2.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.0.5'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'com.github.bumptech.glide:glide:3.7.0'

我看到了许多解决方案,例如gradle的更改

 implementation 'com.android.support:appcompat-v7:28.0.0' 

并设计gradle

  implementation 'com.android.support:design:28.0.0'

我尝试了几乎所有的StackOverflow答案,但都未能成功,谢谢您

1 个答案:

答案 0 :(得分:0)

检查ic_account_circle_24dp是否存在于所有可绘制文件夹中,并确认图像未损坏。

Android自身在添加抽屉时会创建几个像drawable-v24的文件夹。确保您也删除了该文件夹。