Set Title Gravity To Center In Actionbarsherlock
Hello I would like to apply a custom Backgroundlayout just for my Main Activity. I couldn't find a solution. Can somebody give me some tips? would like to have just a simple TextV
Solution 1:
You have to set a custom layout for the Actionbar like this:
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.yourlayout);
In your layout you can then add a TextView and set its gravity to center
. E.g.:
<LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:background="#000000"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="Header!"android:id="@+id/mytext"android:textColor="#ffffff"android:textSize="25dp" /></LinearLayout>
Then you can set your custom typefont inside your Activity from your assets like this:
TextViewtxt= (TextView) findViewById(R.id.mytext);
Typefacefont= Typeface.createFromAsset(getAssets(), "yourfont.ttf");
txt.setTypeface(font);
Post a Comment for "Set Title Gravity To Center In Actionbarsherlock"