Search code examples
androidandroid-appcompatdrawerlayoutandroid-toolbarandroid-actionmode

AppCompat Toolbar stays visible when ActionMode is on


My app contains a DrawerLayout and inside it I include the appcompat toolbar. Everything works fine when the drawer "opens" the fragments but when from fragment I start an activity and then it shows the action mode menus, they are shown on top of the toolbar but I want it over the toolbar in the same manner fragments work.

This effect is present on Android 5.0.1 and KitKat 4.4.2

No solution found on SO worked for me.

How can I fix it and show only the action mode over the toolbar when action mode menus are visible?

The image below shows the wrong result ActionMode and Toolbar

This is the expected result enter image description here

The called activity layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <include layout="@layout/toolbar_app"/>
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

The toolbar layout

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
                                   xmlns:app="http://schemas.android.com/apk/res-auto"
                                   android:id="@+id/my_toolbar"
                                   android:layout_height="wrap_content"
                                   android:layout_width="match_parent"
                                   android:minHeight="?attr/actionBarSize"
                                   app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                                   app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                                   android:background="?attr/colorPrimary"/>

Solution

  • Adding <item name="windowActionModeOverlay">true</item> to the style will fix the issue