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

来源:互联网 发布:最霸气的纹身 知乎 编辑:程序博客网 时间:2024/06/05 09:28

前言

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后问题解决了。

0 0