1

The default App icon and options menu item appear on the left side of the action bar. I would like the options menu to appear on the right side of the menu bar.

I have used a custom view to display other buttons on the action bar towards the right, but the default options menu item still appears on the left.

I am basically facing this issue while implementing the navigation drawer. For my app the user should be able to tap on a menu item placed on the right end of the action bar which will draw out the navigation drawer. Currently the default implementation invokes the navigation drawer on the click of the options menu which appears on the left side of the action bar by default.

Thanks!

user1122549
  • 664
  • 1
  • 13
  • 27
  • This is your answer (http://stackoverflow.com/questions/12750013/actionbar-logo-centered-and-action-items-on-sides) – Sadegh Jul 24 '13 at 15:56

2 Answers2

0
this is an xml

    <android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_gravity="right"

    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <!-- As the main content view, the view below consumes the entire
             space available using match_parent in both dimensions. -->
        <FrameLayout
     android:id="@+id/content_frame"
     android:layout_width="match_parent"
     android:layout_height="match_parent" >



        </FrameLayout>





                <ListView
                 android:id="@+id/right_drawer"
                 android:layout_width="400dp"
                 android:layout_height="600dp"
                 android:choiceMode="singleChoice"
                 android:divider="@android:color/transparent"
                 android:dividerHeight="0dp"
                 android:background="#111"/>






    </android.support.v4.widget.DrawerLayout>
aNiKeT
  • 96
  • 1
  • 5
0
    Java code :

    @Override
onCreate()
{
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerList = (ListView) findViewById(R.id.right_drawer);

        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
                GravityCompat.START);
        mDrawerLayout.setAlpha((float)0.8);


        mDrawerList.setAdapter(adapter);
        mDrawerList.setClickable(false);
        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());



mDrawerToggle = new ActionBarDrawerToggle(this, // host Activity
                mDrawerLayout, // DrawerLayout object
                R.drawable.ic_drawer, // nav drawer image to replace 'Up' caret
                R.string.drawer_open, // "open drawer" description for
                                        // accessibility
                R.string.drawer_close // "close drawer" description for
                                        // accessibility
        ) {
            public void onDrawerClosed(View view) {
                // getActionBar().setTitle(mTitle);
                // invalidateOptionsMenu(); // creates call to
                // onPrepareOptionsMenu()
            }

            public void onDrawerOpened(View drawerView) {
                // getActionBar().setTitle(mDrawerTitle);
                // invalidateOptionsMenu(); // creates call to
                // onPrepareOptionsMenu()
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);


        if (savedInstanceState == null) {
            selectItem(0);
        }

}
        public boolean onCreateOptionsMenu(Menu menu) {
            // TODO Auto-generated method stub
            SubMenu filter = menu.addSubMenu(" ");
            subFilter = filter.getItem().setVisible(true);
            filter.setIcon(R.drawable.ico_filter);
            subFilter.setShowAsAction(android.view.MenuItem.SHOW_AS_ACTION_ALWAYS);
            return true;
        }

        public boolean onPrepareOptionsMenu(Menu menu) {
            // If the nav drawer is open, hide action items related to the content
            // view
            boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
            subFilter.setVisible(!drawerOpen);
            return super.onPrepareOptionsMenu(menu);
        }

        public boolean onOptionsItemSelected(MenuItem menuItem) {
            if (menuItem.equals(subFilter)) {
                if (mDrawerLayout.isDrawerOpen(Gravity.END) == true) {
                    mDrawerLayout.closeDrawers();

                } else {
                    mDrawerLayout.openDrawer(Gravity.END);

                }

            } else {
                onBackPressed();

            }

            return true;
        }
aNiKeT
  • 96
  • 1
  • 5