使用MaterialSearchView遇到android.view.InflateException解决方法

    xiaoxiao2021-04-17  37

    前言

    MaterialSearchView是一个Material风格的第三方搜索控件,本人使用的1.4.0版本。 github地址:https://github.com/MiguelCatalan/MaterialSearchView

    说明

    在项目中引入该库后报了以下错误:

    Caused by: android.view.InflateException: Binary XML file line #41: Binary XML file line #41: Error inflating class com.miguelcatalan.materialsearchview.MaterialSearchView

    本人的xml文件代码

    <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout 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" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="com.textbooking.textbookunlimited.ui.common.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:elevation="0dp"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" /> <com.miguelcatalan.materialsearchview.MaterialSearchView android:id="@+id/search_view" android:layout_width="match_parent" android:layout_height="wrap_content" /> </android.support.design.widget.AppBarLayout> <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/gray100" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> <com.aurelhubert.ahbottomnavigation.AHBottomNavigation android:id="@+id/nav" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" app:layout_anchorGravity="bottom" /> </android.support.design.widget.CoordinatorLayout>

    错误分析

    MaterialSearchView不支持android.support.design.widget.CoordinatorLayout的父布局,父布局换成RelativeLayout后问题解决了。

    转载请注明原文地址: https://ju.6miu.com/read-673950.html

    最新回复(0)