I'm trying since several hours to center my title in the action bar horizontally. This is my code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actionBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:layout_gravity="center"
android:gravity="center">
<TextView
android:id="@+id/activityTitle"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="20sp"
android:textColor="#FFFFFF" />
</LinearLayout>
and this is my onCreate()
code in my activity
:
this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);
LayoutInflater inflator = LayoutInflater.from(this);
View v = inflator.inflate(R.layout.custom_action_bar, null);
Typeface tf = Typeface.createFromAsset(getAssets(),"font/myfont.ttf");
((TextView)v.findViewById(R.id.activityTitle)).setTypeface(tf);
((TextView)v.findViewById(R.id.activityTitle)).setText("Test");
getActionBar().setCustomView(v);
getActionBar().setDisplayShowHomeEnabled(false);
The actionbar icon is hided and the title in the correct font, but it is only centered vertically, but not horizontally. How can I do that?