-1

I have an overflow menu in my action bar , it shown in some devices on the upper action bar and in other devices shown in the below action bar, I want to show my overflow menu on the upper action bar in all devices. Please help me.

my overflow menu :

<item
android:id="@+id/menu_overflow"
android:icon="@drawable/color"
android:orderInCategory="11111"
android:showAsAction="always">
<menu>
    <item
        android:id="@+id/whitecolor"
        android:showAsAction="never"
        android:icon="@drawable/colorwhite"
        android:title="white"/>


    <item
        android:id="@+id/yellowcolor"
        android:showAsAction="never"
        android:icon="@drawable/coloryellow"
        android:title="yellow"/>


    <item
        android:id="@+id/redcolor"
        android:showAsAction="never"
        android:icon="@drawable/colorred"
        android:title="red"/>


    <item
        android:id="@+id/bluecolor"
        android:showAsAction="never"
        android:icon="@drawable/colorblue"
        android:title="blue"/>
</menu>
</item>

and my code :

public boolean onOptionsItemSelected(MenuItem menuItem)
    {       
        switch (menuItem.getItemId()) {         
            case R.id.whitecolor:           

                finish();
                break;
            case R.id.yellowcolor:

                finish();
                break;
            case R.id.redcolor:

                finish();
                break;
            case R.id.bluecolor:

                finish();
                break;
        }
        return true;
    }
user1579019
  • 455
  • 1
  • 7
  • 19

3 Answers3

1

If you've developed your application for Android 2.3.x (API level 10) or lower, the contents of your options menu appear at the bottom of the screen when the user presses the Menu button, as shown in below figure.

enter image description here

If you've developed your application for Android 3.0 (API level 11) and higher, items from the options menu are available in the action bar. By default, the system places all items in the action overflow, which the user can reveal with the action overflow icon on the right side of the action bar (or by pressing the device Menu button, if available). To enable quick access to important actions, you can promote a few items to appear in the action bar by adding android:showAsAction="ifRoom" to the corresponding <item> elements

enter image description here

OR

Try to used Toolbar, you can show the overflow on all versions and all devices.

M D
  • 47,665
  • 9
  • 93
  • 114
0

Use Material Design it has built in support due to its design philosophy

Akshay Mukadam
  • 2,388
  • 1
  • 27
  • 40
0

Try this. For example. if you want more then create layout and set it to your action bar.

      ActionBar actionBar = getActivity().getActionBar();
        actionBar.setDisplayOptions(actionBar.getDisplayOptions()
                | ActionBar.DISPLAY_SHOW_CUSTOM);
        ImageView imageView_done = new ImageView(actionBar.getThemedContext());
        imageView_done.setScaleType(ImageView.ScaleType.CENTER);
        imageView_done.setImageResource(R.drawable.ic_action_done);
        ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(
                ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.WRAP_CONTENT, Gravity.RIGHT
                | Gravity.CENTER_VERTICAL
        );
        layoutParams.rightMargin = 40;
        imageView_done.setLayoutParams(layoutParams);
        actionBar.setCustomView(imageView_done);
chain
  • 649
  • 10
  • 22