Daniel
Daniel

Reputation: 1554

How can I make a menu at the bottom of a view

I wanted to I wanted to create a menu at the bottom of my apps similar to this

enter image description here

The menu button is at the bottom of the layout, and when you click on it, it could expand to a list of items. How can I achieve this menu effect? I have looked up action bar in Android, sadly it's only placed at the top. How can I customize it to my purpose?

A xml sketch would be highly appreciated!

Upvotes: 0

Views: 1547

Answers (2)

sulai
sulai

Reputation: 5354

If you want a custom view on the bottom of the page, try using RelativeLayout:

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Your Contents" />

    <LinearLayout
        android:id="@+id/my_bottom_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/transparent_white"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/x" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="5.6 miles" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/overflow" />

    </LinearLayout>

</RelativeLayout>

To handle the overflow-menu you can use PopupMenu like this:

        PopupMenu popupMenu = new PopupMenu(context, view);
        popupMenu.inflate(R.menu.my_menu);
        popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {...});
        popupMenu.show();

Upvotes: 0

user2058839
user2058839

Reputation:

You can split your action bar to see it in the bottom :

In your manifest :

    <activity
        android:name=".MainActivity"
        android:uiOptions="splitActionBarWhenNarrow">
        <intent-filter>
            <meta-data android:name="android.support.UI_OPTIONS"
               android:value="splitActionBarWhenNarrow" />
        </intent-filter>
    </activity>

Then, the action bar will be displayed at bottom.

More informations here : Action Bar - Using split action bar

Upvotes: 2

Related Questions