If you do the inflatemenu of Search view, it will be forced to end.

Asked 2 years ago, Updated 2 years ago, 59 views

If you inflate the menu in Search View as the title says, it will be forced to end. It says that there are no resources, but it comes out as below for some reason.

It only occurs in os4, and there is no problem with os after that. Please give me some advice!

android.view.InflateException: Binary XML file line #0: Error inflating class

Resources$NotFoundException: Resource is not a ColorStateList (color or path)

android searchview

2022-09-22 15:19

1 Answers

It's good that you uploaded the error code! By the way, it would be easier to guess if you also upload the inflating code.

I can't think of anything right away just by looking at the error code. I'll upload the code I wrote!

menu.xml
<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto">

        <item android:id="@+id/menu_item_search"
              android:title="@string/search"
              app:actionViewClass="android.support.v7.widget.SearchView"
              app:showAsAction="ifRoom"/>

</menu>

in fragment

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.fragment_photo_gallery, menu);

    MenuItem searchItem = menu.findItem(R.id.menu_item_search);
    final SearchView searchView = (SearchView) searchItem.getActionView();

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String s) {
        }

        @Override
        public boolean onQueryTextChange(String s) {
        }
    });
    searchView.setOnSearchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        }
    });
}


2022-09-22 15:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.