I have my activity extending AppCompatActivity, and I wish to set a contextual action bar on it. So here is my onCreate method
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
MainActivity.this.startSupportActionMode(new ActionBarCallBack());
My ActionBarCallBack extend android.support.v7.view.ActionMode and I declared it like this
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.contextual_menu, menu);
return false;
}
The theme set on my manifest:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionModeOverlay">true</item>
</style>
MainActivity:
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main2"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
My onCreateActionMode trigger but the CAB never show.
Any ideas?
So here was the error
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.contextual_menu, menu);
return true; // Now it works
}
Set the windowActionModeOverlay to my Theme.NoActionBar
<item name="windowActionModeOverlay">true</item>
Don't have to set the startActionMode() from my toolBar as I saw on over stackoverflow thread. On android.support.v7.view.ActionMode this line just work fine for me.
Main2Activity.this.startSupportActionMode(new ActionBarCallBack()); //android.support.v7.view.ActionMode