Set Title gravity to center in ActionBarSherlock

梦想与她 提交于 2019-11-30 04:14:05

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.:

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000">

    <TextView
        android: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:

 TextView txt = (TextView) findViewById(R.id.mytext);  
 Typeface font = Typeface.createFromAsset(getAssets(), "yourfont.ttf");  
 txt.setTypeface(font);  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!