Reputation: 16268
I want to use actionBar.setIcon()
and have it centered. is this possible?
Already tried using a custom view but the container doesn't get centered.
Upvotes: 1
Views: 1106
Reputation: 16268
Solved. I just overrided the Gravity
property in the custom style
<item name="android:gravity">center</item>
Upvotes: 1
Reputation: 222552
Here is the custom layout,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ActionBartest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
>
<ImageButton
android:id="@+id/slideMenuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_alignParentLeft="true" />
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_centerVertical="true"
android:layout_centerInParent="true" />
</RelativeLayout>
Put this in your code,
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 andView = getLayoutInflater().inflate(R.layout.actionbar, null);
actionBar.setCustomView(andView);
Upvotes: 0