Display ActionMode over Toolbar
Solution 1:
Since you are using the
Toolbar
, I also assume you are using theAppCompatActivity
and have replaced the built inActionBar
with your customToolbar
usingsetSupportActionBar(toolbar);
First of all ensure you are importing the correct namespace:
import androidx.appcompat.view.ActionMode;
// Or
import android.support.v7.view.ActionMode;
and NOT
import android.view.ActionMode;
then use
_actionMode = startSupportActionMode(this);
and NOT
_actionMode = startActionMode(this);
Solution 2:
Do not start it on your activity, but on your toolbar. In you activity:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.startActionMode(mActionModeCallback)
and you have to use
<item name="windowActionModeOverlay">true</item>
in your theme as stated by Andre.
Solution 3:
Try this in your theme:
<item name="windowActionModeOverlay">true</item>
Solution 4:
I think the one thing people are not making clear is that the line
<item name="windowActionModeOverlay">true</item>
is placed in the Base theme i.e AppTheme and not the AppTheme.NoActionBar
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionModeOverlay">true</item>
</style>
<style name="transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Solution 5:
find your AndroidManifest.xml ,next add below code in your application or Activity theme
<item name="windowActionModeOverlay">true</item>
so like:
<style name="WorkTimeListTheme" parent="AppTheme.NoActionBar">
<item name="windowActionModeOverlay">true</item>
<item name="actionModeBackground">@color/theme_primary</item>
</style>