Pranesh Sahu Pranesh Sahu - 6 months ago 31
Android Question

How to make my menu to appear below the Action Bar area

My Question is how i can move my menu dropdown to the space with pink area(see second image).As if now it is appearing in the Action Bar area too that i don't want.I want my menu to be appear just below the Action bar.

Please guys help me out to solve this situation.

enter image description here

This is how menu is coming.

enter image description here

I want my menu to appear just below the Action Bar.

This is how my menu.xml looks like

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.example.mobileinventorysuit.MainActivity" >

<item
android:id="@+id/login_mnu_imports"
android:icon="@drawable/import_menu"
app:showAsAction="always"
style="@style/OverflowMenu"
android:title="Import"/>
<item
android:id="@+id/login_mnu_settings"
android:icon="@drawable/settings_menu"
style="@style/OverflowMenu"
app:showAsAction="always"
android:title="Settings"/>
<item
android:id="@+id/login_mnu_dev"
android:icon="@drawable/dev"
style="@style/OverflowMenu"
app:showAsAction="always"
android:title="Device Info"/>
<item
android:id="@+id/login_mnu_exit"
style="@style/OverflowMenu"
app:showAsAction="always"
android:icon="@drawable/ic_lock_power_off"
android:title="Exit"/>


</menu>

Answer

Actually the ActionBar menu should display on top of the action bar. From the Documentation

A menu is a temporary sheet of paper that always overlaps the app bar, rather than behaving as an extension of the app bar.

If you still want that behaviour you can use this. But its not recommended.

<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow" >
         <item name="overlapAnchor">false</item>
         <item name="dropDownVerticalOffset">?attr/actionBarSize</item>
</style>

Check this answer Why is my overflow dropdown menu on top of the actionbar?

EDIT

If you want icons placed in your ToolBar

add this in menu.xml

 xmlns:app="http://schemas.android.com/apk/res-auto"

and add this line in your menuitems

 app:showAsAction="always"
Comments