In my app I need to use the ActionMode.
I have followed several Guides and Tutorials (https://medium.com/asos-techblog/style-actionmode-on-android-5e613fa77c32, https://developer.android.com/guide/topics/ui/menus e.g.) on implementing my Contextual Action Menu but as you can see in this image:
https://i.sstatic.net/ag2Mp.jpg
There is part of the titleBar still visible on the bottom. My question is if there is anything i can do to change this behaviour.
I also tried to change the style of my ActionModeBar but when i change the styling it becomes invisible (only showing the icons) and the titlebar is completely visible.
I have not made any changes to the ActionMode except the menu that contains the buttons:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/stopCab"
android:title="Stop contextual action bar"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_baseline_cancel_24"/>
<item android:id="@+id/deleteCab"
android:title="Delete selected items"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_delete_white_24dp"/>
</menu>
Initializing the ActionMode:
private ActionMode.Callback actionModeCallback = new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.contextual_action_bar_menu, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.deleteCab:
//TODO: do something
return true;
case R.id.stopCab:
//TODO: do something
return true;
default:
return false;
}
}
@Override
public void onDestroyActionMode(ActionMode actionMode) {
FieldChooserActivity.this.actionMode = null;
}
};
And starting the ActionMode:
FieldChooserActivity.this.actionMode = startActionMode(FieldChooserActivity.this.actionModeCallback);
In my Style the AppTheme parent is Theme.AppCompat.Light.DarkActionBar And each Activity has
android:theme="@style/AppTheme.NoActionBar">
in AndroidManifest. Maybe this is the fault why i cant change the style without the ActionMode becoming invisible.
I hope someone can help me with this matter and thanks in advance!
I found a solution that fixed my problem (where the ActionMode bar doesn't cover the Toolbar).
As i looked at the layout of my activity i saw that in the Toolbar is a height attribute called '?attr/actionBarSize':
<androidx.appcompat.widget.Toolbar
android:id="@+id/fieldChooserToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
I then added the height to a custom style for my ActionMode:
<style name="ActionModeTheme" parent="AppTheme">
<item name="windowActionModeOverlay">true</item>
<item name="actionModeCloseDrawable">@drawable/ic_delete_white_24dp</item>
<item name="actionMenuTextColor">@android:color/white</item>
<item name="height">?attr/actionBarSize</item>
<item name="background">@color/colorSecondary</item>
<item name="android:src">@drawable/ic_baseline_close_24</item>
</style>
The last part was that i added following line to my AppTheme-styling:
<item name="actionModeStyle">@style/ActionModeTheme</item>
And then it worked!
The second problem where my ActionMode bar was invisible was most likely caused by adding the actionModeStyling to the AppTheme.NoActionBar.