Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MenuItemCompat.getActionView is Deprecated

I am implementing a SearchView like this:

    MenuItem search = menu.findItem(R.id.search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(search);

But this gives me an inspection report

'getActionView(android.view.MenuItem)' is deprecated

Now in the docs, it is mentioned:

This method was deprecated in API level 26.0.0

Use getActionView() directly.

So I tried this:

    MenuItem search = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) getActionView(search);

But it still gives me the deprecated message. So what is the best practice?

like image 741
Kartik Shandilya Avatar asked Sep 03 '17 05:09

Kartik Shandilya


1 Answers

Try:

MenuItem search = menu.findItem(R.id.search);
SearchView searchView = (SearchView) search.getActionView();

getActionView is deprecated?

like image 152
swerly Avatar answered Oct 22 '22 08:10

swerly