Jacob Anthony Tonna
Jacob Anthony Tonna

Reputation: 525

How To Center Text In Android Action Bar?

i have tryed others answer from this site but they dont work for me here is what i have so far

styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ActionBar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@drawable/actionbar_background</item>
</style>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
</resources>

actionbar_background.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ios_actionbarbg"
android:tileMode="repeat" />

what do i have to do so my application name text will be in the Center ??

Upvotes: 0

Views: 5150

Answers (1)

Tom Fobear
Tom Fobear

Reputation: 6749

menu_example.xml:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent
    android:orientation="horizontal" />
    <TextView
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="My activity title">
    </TextView>
</LinearLayout>

ActivityExample.java:

@Override
protected void onCreate(Bundle b) {
    super.onCreate(b);
    getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    getActionBar().setCustomView(R.layout.menu_example);
}

Upvotes: 2

Related Questions