Skip to content Skip to sidebar Skip to footer

Searchmenuitem.getactionview() Returning Null

getActionView() is retuning null. What am i doing wrong? I am extending Activity and using android:minSdkVersion='11' android:targetSdkVersion='19' menu.methodXXX() use MenuCompat.methodXXX(menu) )

Now, to define a actionViewClass(and others attributes added in api newer then 11) in menu you should use the app namespace for this instead android namespace

so android:actionViewClass should become app:actionViewClass

in the code you should use MenuItemCompat.getActionView(searchItem) instead searchItem.getActionView()

remeber to add namespace app in root element of menu xml file like xmlns:app ="http://schemas.android.com/apk/res-auto"

also small hint (as you are using 11 as min sdk your code should works fine but ...) replace android.widget.SearchView to android.support.v7.widget.SearchView as it(standard SearchView) not works in the same way on different API versions from 11 to newest one(also you will get method not found if you use methods added in API > 11 to SearchView on devce with API 11)

Post a Comment for "Searchmenuitem.getactionview() Returning Null"