android - How to center title in ActionBarSherlock with menu items? -
in order center title in topbar, set custom view actionbarsherlock this:
ab.setdisplayshowcustomenabled(true); ab.setdisplayoptions(actionbar.display_show_custom); ab.setcustomview(r.layout.topbar);
my custom view:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/textview" android:layout_width="fill_parent" android:layout_height="40dp" android:padding="5dp" android:background="#00ff00" > <imageview android:id="@+id/sidemenubutton" android:layout_width="40dp" android:layout_height="40dp" android:layout_centervertical="true" android:src="@drawable/icon_menu" /> <imageview android:layout_width="300dp" android:layout_height="wrap_content" android:layout_centerinparent="true" android:src="@drawable/logo" /> </relativelayout>
and well, works - until shows menu buttons (buttons on right).
they inflated:
@override public boolean oncreateoptionsmenu(menu menu) { getsupportmenuinflater().inflate(r.menu.main_menu, menu); //... }
items:
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/menu_share" android:actionproviderclass="com.actionbarsherlock.widget.shareactionprovider" android:icon="@drawable/icon_foo" android:showasaction="always" android:title="@string/foo" android:visible="false"/> //... </menu>
how can whole layout of topbar - such if "center", centers in available width? don't have problems possible overlapping, since centered logo , menu items images fixed size.
i measuere width of screen , set left margin dynamically, hope there's better solution this.
thanks in advance.
Comments
Post a Comment