How to create menu items aligned horizontally in the first row like google chrome
I created the first item with a menu child but by this way i got a row that send me to the other menu, So how to do that using menu file ? i don't want to use Dialog
Here is my menu file :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:id="@+id/toolbar_menu"
android:visible="true">
<item
android:id="@+id/item_tabs"
android:icon="@drawable/ic_tabs_24dp"
android:title="@null"
app:showAsAction="always"/>
<item
android:id="@+id/icon_row_menu_id"
android:title="@null"
android:visible="true">
<menu>
<item
android:id="@+id/item_back"
android:icon="@drawable/ic_arrow_back_24dp"
android:title="@string/go_back" />
<item
android:id="@+id/item_forward"
android:icon="@drawable/ic_arrow_forward_24dp"
android:title="@string/go_forward" />
<item
android:id="@+id/item_bookmark_page"
android:icon="@drawable/ic_star_border_24dp"
android:title="@string/bookmark_this_page" />
<item
android:id="@+id/item_download_page"
android:icon="@drawable/ic_download_24dp"
android:title="@string/download_page" />
<item
android:id="@+id/item_info"
android:icon="@drawable/ic_info_outline_24dp"
android:title="@string/view_site_information" />
</menu>
</item>
<item
android:id="@+id/item_new_tab"
android:title="@string/new_tab" />
<item
android:id="@+id/item_new_incognito_tab"
android:title="@string/new_incognito_tab" />
<item
android:id="@+id/item_bookmarks"
android:title="@string/bookmarks" />
<item
android:id="@+id/item_history"
android:title="@string/history" />
<item
android:id="@+id/item_downloads"
android:title="@string/download" />
<item
android:id="@+id/item_settings"
android:title="@string/settings" />
</group>
</menu>
And here how i use it :
@Override
public boolean onCreateOptionsMenu(Menu menu) {
mainMenu = menu;
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
To horizontally center a block element (like <div>), use margin: auto; Setting the width of the element will prevent it from stretching out to the edges of its container.
style="overflow:hidden" for parent div and style="float: left" for all the child divs are important to make the divs align horizontally for old browsers like IE7 and below. For modern browsers, you can use style="display: table-cell" for all the child divs and it would render horizontally properly.
You can use app:actionLayout="@layout/layout_name"
property of item tag like
<item
android:id="@+id/menu_id"
android:title="@string/title"
app:showAsAction="never"
app:actionLayout="@layout/layout_name"/>
and your layout_name
is any layout file like
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
// add your horizontal menu item here
</LineearLayout>
and you can access this item
@Override
public boolean onPrepareOptionsMenu(Menu menu)
{
MenuItem item = menu.findItem(R.id.menu_id);
Linearlayout rootView = (LinearLayout)item.getActionView();
YourControlClass control = (YourControlClass)
rootView.findViewById(R.id.control_id);
return true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With