I have updated holoeverywhere version in my project so I not longer use ActionBarSherlock (ABS) but ActionBarCompact (ABC)
The problem I have is when using MenuItemCompat.getActionView(aMenuItem) I always get a null value.
The exact code I have is:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.dashboard_menu, menu);
_itemNotifications = menu.findItem(R.id.notifications);
_containerViewItemNotifications = (LinearLayout) MenuItemCompat.getActionView(_itemNotifications);
_viewItemNotifications = (TextView) _containerViewItemNotifications.findViewById(R.id.ActionViewDashboard);
_containerViewItemNotifications.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
public void onClick(View v) {
if (android.os.Build.VERSION.SDK_INT >= 16) {
_viewItemNotifications.setBackground(getResources().getDrawable(R.drawable.qnotificacion_disbled));
} else {
_viewItemNotifications.setBackgroundDrawable(getResources().getDrawable(R.drawable.qnotificacion_disbled));
}
_viewItemNotifications.setText(R.string.empty);
onOptionsItemSelected(_itemNotifications);
}
});
_itemAnotateResult = menu.findItem(R.id.menu_anotate_result);
return super.onCreateOptionsMenu(menu);
}
where MenuItemCompat.getActionView(_itemNotifications) is always a null value
My XML menu file is like this:
<?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/notifications"
android:actionLayout="@layout/actionview_dashboard"
android:title="@string/customize"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_anotate_result"
android:title="@string/anotate"
android:visible="false"
app:showAsAction="ifRoom|withText"/>
</menu>
How can I overcome this? I have tried to follow a similar approach to what is explained for SearchViewItem on android's documentation but no success at all
Thanks in advance.
I think the problem lies with the fact that ABC does not support custom ActionLayouts. I found a person who faced a similar problem which he resolved successfully. While adding SearchView, note that he used app:actionViewClass. Could you try to use app:actionLayout and see if it works for you?