可以使用自訂的layout檔案來完成
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="YOUR ACTIVITY TITLE"
android:textColor="#ffffff"
android:textSize="24sp" />
</LinearLayout>
然後在你的程式碼getActionBar的同時,把自訂的layout設定進去便可
ActionBar bar = getActivity().getActionBar(); bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); bar.setCustomView(R.layout.actionbar);
![[Android SDK特色教學] ActionBar文字標題置中 [Android SDK特色教學] ActionBar文字標題置中](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7-4wnusSZclW2ocald_8EnUGfl96-_x_Snbkfn1k9Zy9t4GMUy8R4mdfvupRythhneyOA2vrv_vbvfEkl5X7HJLCX5ptJXEWyyjxDHRUksAPSUagIX_PhDU_qUGWBEFrJsrGkJbpHdyY/s1600/device-2014-06-11-185617.png)
沒有留言 :
張貼留言