Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contextual action bar does not overlay my toolbar

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;
    }
like image 326
Edijae Crusar Avatar asked Nov 17 '15 11:11

Edijae Crusar


People also ask

How do I get the toolbar from action bar?

if you are using custom toolbar or ActionBar and you want to get reference of your toolbar/action bar from Fragments then you need to first get instance of your Main Activity from Fragment's onCreateView Method like below. ImageView vRightBtn = activity. toolbar.

What is the difference between a toolbar and an action bar?

An Action bar is traditionally a part of an Activity opaque window decor controlled by the framework but a Toolbar may be placed at any level of nesting within a view hierarchy. The toolbar provides more feature than ActionBar . A Toolbar may contain a combination of elements from start to end.

How do you display action bar back button on all versions of Android?

Show back button using actionBar. setDisplayHomeAsUpEnabled(true) this will enable the back button. Custom the back event at onOptionsItemSelected. This will enable the back function to the button on the press.

How do you add action items to the action bar in Android?

All action buttons and other items available in the action overflow are defined in an XML menu resource. To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.


2 Answers

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>
like image 102
Rajesh Avatar answered Sep 18 '22 14:09

Rajesh


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>
like image 45
Lins Louis Avatar answered Sep 20 '22 14:09

Lins Louis