Display ActionMode over Toolbar

30,230

Solution 1

Since you are using the Toolbar, I also assume you are using the AppCompatActivity and have replaced the built in ActionBar with your custom Toolbar using setSupportActionBar(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>
Share:
30,230
Gaëtan
Author by

Gaëtan

Updated on January 15, 2021

Comments

  • Gaëtan
    Gaëtan over 3 years

    I am trying to use the android.view.ActionMode with the new android.support.v7.widget.Toolbar, in addition to the traditional android.app.ActionBar. I am able to display it with:

    toolbar.startActionMode(callback);
    

    The problem is that the ActionMode is displayed over the ActionBar, and not over the Toolbar. Is there a way to change that?

    I tryied to set the following in my theme, but it does not seem to change anything:

    <item name="windowActionModeOverlay">true</item>