I just would like to tweak the View of an ActionBar MenuItem by code.
Unfortunately, it seems that getActionView always return null!
My code:
getActionView()
only works if there's a custom actionView from setActionView
.
you should use
app:actionLayout="@layout/menu_actionbar_basket"
thats the trick if you use
android:actionLayout="@layout/menu_actionbar_basket"
you would always get null exception in default toolbar.
If your debug build is working without any issues and issue is only with release build then this may be because of proguard configuration. If you have enabled proguard in your application then add below line to proguard-rules.pro
-keep class android.support.v7.widget.SearchView { *; }
For me the solution that worked is to use app namespace instead of android.
app:actionViewClass="android.support.v7.widget.SearchView"
Don't forget to declare it:
xmlns:app="http://schemas.android.com/apk/res-auto"
First Solution
This happen may be you not set actionLayout in Menu file so set your actionLayout in menu file
app:actionLayout="@layout/your_action_layout"
Second Solution and the second solution is
from
android:actionLayout="@layout/your_action_layout"
to
app:actionLayout="@layout/your_action_layout"