user3496326
user3496326

Reputation: 131

Android - How to use menu option on mobiles which doesn't have a menu button?

I have a project which uses the mobile's menu button. but some mobiles don't have an option to get the menu [ex: Moto G] instead they use action bar but that's not supported on Android 2.1. I want the menu to work on both Android 2.1 as well as 4.4 how do i do that?

Upvotes: 0

Views: 481

Answers (4)

kodartcha
kodartcha

Reputation: 1073

Why not using the support library v7, which contains support action bar (which inclueds menu buttons on actionb bar) with AppCompat theme. You will have action bar with menu buttons for versions lower than 3.0. It will work from Android 2.1.

Read THIS about Support Library v7.

And check THIS example on how to make an application using AppCompat Theme.

Upvotes: 0

DDsix
DDsix

Reputation: 1984

You can create a custom button and call openOptionsMenu(); when is clicked.

Edit:

Disable the default settings button on the action bar and add this one

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/settings_button"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:padding="10dp"
    android:orientation="vertical">

    <View
        android:layout_width="5dp"
        android:layout_height="5dp"
        android:background="@color/black"
        android:layout_margin="2dp"/>

    <View
        android:layout_width="5dp"
        android:layout_height="5dp"
        android:background="@color/black"
        android:layout_margin="2dp"/>

    <View
        android:layout_width="5dp"
        android:layout_height="5dp"
        android:background="@color/black"
        android:layout_margin="2dp"/>
    </LinearLayout>

Upvotes: 0

starkst
starkst

Reputation: 11

2 ways to Achieve this:

Create a button (say menu) and add it to the Action Bar. Implement your own method (Eg: Spinner) to display the options as a drop down once the button is clicked which serves as menu.

The other way is to create a context Menu

Upvotes: 1

Marcin Orlowski
Marcin Orlowski

Reputation: 75619

This is article you need to read: Say Goodbye to the Menu Button

If your app runs on a device without a dedicated Menu button, the system decides whether to add the action overflow to the navigation bar based on which API levels you declare to support in the manifest element. The logic boils down to:

If you set either minSdkVersion or targetSdkVersion to 11 or higher, the system will not add the legacy overflow button.

Otherwise, the system will add the legacy overflow button when running on Android 3.0 or higher.

The only exception is that if you set minSdkVersion to 10 or lower, set targetSdkVersion to 11, 12, or 13, and you do not use ActionBar, the system will add the legacy overflow button when running your app on a handset with Android 4.0 or higher.

Upvotes: 1

Related Questions