Aan
Aan

Reputation: 308

Error inflating class android.support.v7.widget.SearchView - android

I am implementing a searchView in my Fragment class. But there is this error. When I tried to debug as well, the app is crashed with this error.

There were some similar issues as seen in stackoverflow, but none of them solved the issue, so I created a new question

Here is my code:

<android.support.constraint.ConstraintLayout 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="wrap_content"
android:focusable="true"
android:background="@color/colorBackground"
android:focusableInTouchMode="true"
tools:context="com.work.ksd.HomePage">

<android.support.v7.widget.SearchView
    android:id="@+id/searchView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:padding="0dp"
    app:queryHint="Search products"
    app:iconifiedByDefault="false"
    android:elevation="5dp"
    android:focusable="false"
    android:forceHasOverlappingRendering="false"
    android:focusableInTouchMode="false"
    app:theme="@style/AppSearchView"
    app:queryBackground="@android:color/transparent"
    android:background="@drawable/register_textview_background"
    android:layout_marginRight="10dp"
    app:layout_constraintRight_toRightOf="parent"
    android:layout_marginLeft="10dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="10dp"
    android:layout_marginStart="10dp"
    android:layout_marginEnd="10dp"/>

</android.support.constraint.ConstraintLayout>

On the CreateView method of fragment I've:

SearchView searchView = (SearchView) view.findViewById(R.id.searchView);

The error is

    android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class android.support.v7.widget.SearchView

Upvotes: 1

Views: 1987

Answers (1)

Amir daraei
Amir daraei

Reputation: 63

You need to use

<androidx.appcompat.widget.SearchView

Instead of

<android.support.v7.widget.SearchView

your xml code:

<android.support.constraint.ConstraintLayout 
   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="wrap_content"
   android:focusable="true"
   android:background="@color/colorBackground"
   android:focusableInTouchMode="true"
   tools:context="com.work.ksd.HomePage">

<androidx.appcompat.widget.SearchView
    android:id="@+id/searchView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:padding="0dp"
    app:queryHint="Search products"
    app:iconifiedByDefault="false"
    android:elevation="5dp"
    android:focusable="false"
    android:forceHasOverlappingRendering="false"
    android:focusableInTouchMode="false"
    app:theme="@style/AppSearchView"
    app:queryBackground="@android:color/transparent"
    android:background="@drawable/register_textview_background"
    android:layout_marginRight="10dp"
    app:layout_constraintRight_toRightOf="parent"
    android:layout_marginLeft="10dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="10dp"
    android:layout_marginStart="10dp"
    android:layout_marginEnd="10dp"/>

</android.support.constraint.ConstraintLayout>

Upvotes: 1

Related Questions