I’m trying to center the icon in the android action bar. I’m using a custom layout that has a button on the left side, an icon in the center and the menu options on the right.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ActionBarWrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/slideMenuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_bookmark" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_centerInParent="true" />
</RelativeLayout>
</RelativeLayout>
I’ve tried this with and without the RelativeLayout wrapping the ImageView. The left button shows up fine, and I can set the icon with layout_toRightOf, but I can’t get it to center. Anyone have any ideas?
Edit:
Here’s the android code in the on create method.
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayOptions(actionBar.DISPLAY_SHOW_CUSTOM);
View cView = getLayoutInflater().inflate(R.layout.actionbar, null);
actionBar.setCustomView(cView);
Okay. This should work. Try this(Tested in normal activity):