javaandroidxmlandroid-toolbarcontextual-action-bar

Contextual Action Bar (CAB) does not overlay Toolbar


I am really stuck with this.

I want to use a CAB in a fragment, so I'm using

actionMode = ((MainActivity)getActivity()).startActionMode(actionModeCallbacks);

to call startActionMode

I've been changing themes and adding and testing several lines of code (together and separated) to xml styles like:

<item name="android:windowActionModeOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowActionBar">false</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowActionBarOverlay">true</item>

Relevant information:

My toolbar (*android.support.v7.widget.Toolbar):

        toolbar = findViewById(R.id.toolbar);

        mDrawerLayout = findViewById(R.id.drawer_layout);

        toolbar.setTitle(R.string.addWordLabel_Act);
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);

XML (toolbar)

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#FAFAFA"
        android:theme="@style/AppTheme.NoActionBar"
        app:collapseIcon="@drawable/ic_arrow_back_white_24dp"
        app:contentInsetStartWithNavigation="0dp"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:title="@string/addWordLabel_Act"
        app:titleTextColor="@color/colorAccent"
        />

</android.support.constraint.ConstraintLayout>

ActionMode.Callback

        private ActionMode actionMode;


private  ActionMode.Callback actionModeCallbacks = new ActionMode.Callback() 
        {
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.getMenuInflater().inflate(R.menu.action_mode_menu, menu);
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {

            switch (item.getItemId()) {
                case R.id.share_actionMode:
                    shareWord();
                    mode.finish();
                    return true;
                case R.id.deleteWords_actionMode:
                    deleteWords();
                    mode.finish();
                    return true;
                default:
                    return false;
            }

        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            actionMode = null;
        }
    };

XML (CAB)

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:title="Share"
        android:icon="@drawable/ic_share_white_24dp"
        android:id="@+id/share_actionMode"/>

    <item android:id="@+id/deleteWords_actionMode"
        android:title="Delete"
        android:icon="@drawable/ic_round_delete_outline_white_24px"/>

</menu>

And styles...

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/lightAccent</item>
    <item name="colorSecondary">@color/colorSecondary</item>
    <item name="android:fontFamily">@font/sans_serif_roboto</item>
    <item name="alertDialogTheme">@style/AlertDialogStyle</item>
    <item name="android:windowActionModeOverlay">true</item>

</style>

<style name="AppTheme.NoActionBar" 
    parent="Theme.MaterialComponents.NoActionBar">

</style>

I don't know what else I can do.


Solved

I completely forgot to check Manifest, and that was the problem! The AppTheme was set to "Theme.AppCompat.Light.NoActionBar" instead of "AppTheme". Thus, any change I made in AppTheme didn't take effect on the App.


Solution

  • I completely forgot to check Manifest, and that was the problem! The AppTheme was set to "Theme.AppCompat.Light.NoActionBar" instead of "AppTheme". Thus, any change I made in AppTheme didn't take effect on the App.