0

these are my menus :

    <item
    android:id="@+id/search"
    android:icon="@drawable/ic_action_search"
    android:orderInCategory="2"
    android:title="@string/search"
    yourapp:showAsAction="always|withText"/>
<item
    android:id="@+id/newadd"
    android:icon="@drawable/ic_action_new"
    android:orderInCategory="3"
    android:title="@string/newadd"
    yourapp:showAsAction="always|withText"/>
<item
    android:id="@+id/sort"
    android:icon="@drawable/ic_action_sort_by_size"
    android:orderInCategory="1"
    yourapp:showAsAction="always"/>

when I run the app , all 3 of them are on the right side of actionbar , How can I make them to move to left side of actionbar ?

also , I've an navigationDrawer , the icon is on the left side and I want to move it to the right side , How can I do so ?

I don't have any search on my actionbar .

How can I do so ?

thanks

mohsen
  • 451
  • 2
  • 6
  • 15

2 Answers2

1

You can use custom views for actionbar

ActionBar mActionBar = getActionBar();
View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);

actionbar xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/activity_horizontal_margin" >

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

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/imageView1"
        android:paddingLeft="12dp"
        android:paddingRight="12dp"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/imageView2"
        android:paddingLeft="12dp"
        android:paddingRight="12dp"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

set these methods for actionbar to make navigation drawer home icon visible

  getActionBar().setBackgroundDrawable(
                    new ColorDrawable(Color.parseColor("#56B1D8"))); //$NON-NLS-1$
            LayoutInflater inflator = (LayoutInflater) this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            ActionBar actionBar = getActionBar();
            getActionBar().setDisplayShowCustomEnabled(true);
            actionBar.setDisplayShowTitleEnabled(false);
            // actionBar.setDisplayUseLogoEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayUseLogoEnabled(false);
            actionBar.setDisplayShowHomeEnabled(false);
            // getActionBar().setIcon(R.drawable.ic_navigation_drawer);
            // navigation icon on actionbar
            actionBar.setHomeButtonEnabled(true);
            actionBar.setIcon(null);
SHASHIDHAR MANCHUKONDA
  • 3,302
  • 2
  • 19
  • 40
  • Iv'e tried that , What should be the content of custom_actionbar layout ? for making 3 image buttons on actionbar and navigationDrawer ? – mohsen Sep 21 '14 at 06:34
0

Assuming you're a right-to-left reader and trying to support such. As for the app as a whole I believe it takes its cues from your device's selected language and locale. Forcing right-to-left? IDK how to do that, but to flip the actionbar as you've described I suspect that's what you'd be doing.

Aside from that just make sure you're using start and end vs. left and right for other alignments. Both start and end will honor your devices settings where as left and right will not.

Bill Mote
  • 12,644
  • 7
  • 58
  • 82