Contextual action bar does not overlay my toolbar
Asked Answered
H

5

20

I have created an activity and set toolbar as the actionbar which i have positioned at the bottom.

Inside that activity, I have a listview that contain some data.

Problem is, when I long press a list item, contextual action bar appears at the top instead of overlaying my toolbar which is positioned at the bottom.

my activity theme

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="myActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="android:windowActionModeOverlay">true</item>
</style>

my toolbar

<android.support.v7.widget.Toolbar
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:id="@+id/toorbar"
    android:background="@android:color/white"
    android:layout_gravity="bottom">
</android.support.v7.widget.Toolbar>

my activity

protected void onCreate(Bundle savedInstanceState){
    ToolBar toolbar =(ToolBar) findViewById(R.id.toolbar)
    setSupportActionBar(toolbar)
}

What should i do to make CAB overlay my toolbar?

EDIT

This is onCreateActionMode method in my class that handle long clicks

private class Selector implements AbsListView.MultiChoiceModeListener{

    @Override
    public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
        mode.getMenuInflater().inflate(R.menu.my_activity_menu,menu);
        toolbar.setVisibility(View.VISIBLE);
        return true;
    }
Hulsey answered 17/11, 2015 at 11:34 Comment(7)
why are u showing toolbar in onCreateActionMode using toolbar.setVisibility(View.VISIBLE); ??Salimeter
You need to remove that lineSalimeter
@RajeshJadav i only want the toolbar(now my actionbar) to be visible when one long press a list item. i then set it to INVISIBLE when an action has beentakenHulsey
Actually you do not need to do that. when you use windowActionModeOverlay to true. contectuctual actionbar replaces toolbar but you are showing toolbar in onCreateActionMode which is not required. when you click on done button in contectuctual actionbar then toolbar automatically replaces contectuctual actionbarSalimeter
@RajeshJadav i don't know why this CAB still think i have an actionbar at the top! imagine even after removing that toolbar.setVisibliity line. it stills shows at the top of my activityHulsey
@RajeshJadav have any other suggestion boss?Hulsey
can you show your app screenshot?Salimeter
H
0

Since my toolbar was at the bottom of the activity, solution was to make my own contextual action bar that will overlay it.

This project below gave me a head start.

https://github.com/afollestad/material-cab

Hulsey answered 25/5, 2018 at 12:23 Comment(0)
S
51

If you want the Contextual ActionBar overlap over Toolbar then use this

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

instead of

<item name="android:windowActionModeOverlay">true</item>
Salimeter answered 17/11, 2015 at 11:47 Comment(10)
i have tried teven removing android namespace but it still appears at the top instead of overlaying my toolbar at the bottomHulsey
your edit is exactly what i have used in my question and still problem appearsHulsey
no Parent theme is different in edit. it is Theme.AppCompat.NoActionBar instead of Theme.AppCompat.Light.NoActionBar and also need to remove <item name="windowActionBar">false</item>Salimeter
problem still appears even after changing parent to Theme.AppCompact.NoActionBarHulsey
which Activity you are using AppCompatActivity?Salimeter
my activity extends ActionBarActivity(by the way it is marked as depricated)Hulsey
pls check by Extending AppCompatActivity instead of ActionBarActivitySalimeter
that doesnt solve my problem. please see my EDIT on how i have implemented oncreateactionmodeHulsey
It solves my issue exactly i removed android:windowActionModeOverlay to windowActionModeOverlay ,Thanks alotEviaevict
@Rajesh It's have been a long time. I can see your answer has helped many people here solve the same problem so I'm going to accept it.Hulsey
T
3

This worked For me,

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

            <item name="windowNoTitle">true</item>
            <item name="windowActionBar">false</item>
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
            <item name="windowActionModeOverlay">true</item>

     </style>
Tamqrah answered 11/1, 2018 at 7:0 Comment(0)
D
1

you can try this theme this may solve your problem.

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

 </style>
Dashed answered 17/11, 2015 at 11:43 Comment(1)
This doesn't solve the problem. it only changes CAB's theme/style but not moving it to bottom where my toolbar is locatedHulsey
F
0
<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/color_primary</item>
        <item name="colorPrimaryDark">@color/color_primary_dark</item>
        <item name="colorAccent">@color/color_accent</item>

        <item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>

        <!-- required for toolbar in prelolipop -->
        <item name="android:windowNoTitle">true</item>
        **<item name="windowActionModeOverlay">true</item>**

    </style>

use <item name="windowActionModeOverlay>true</item> for Contextual action bar to overlay toolbar. And remove if you have used <item name="windowActionBar">false</item>. It worked for me.

Felix answered 20/10, 2016 at 11:55 Comment(0)
H
0

Since my toolbar was at the bottom of the activity, solution was to make my own contextual action bar that will overlay it.

This project below gave me a head start.

https://github.com/afollestad/material-cab

Hulsey answered 25/5, 2018 at 12:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.