使用工具欄,而不是ActionBar.follow以下步驟添加工具欄:從文件菜單,轉到庫 1.更改你的應用程序的主題,Theme.AppCompat.Light.NoActionBar
2.Goto項目結構依賴關係,添加設計庫並同步您的項目。 3.Goto佈局要顯示動作條,寫下面的代碼:
<android.support.v7.widget.Toolbar
android:id="@+id/mytoolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/pccolor"
android:title="Services"
app:titleTextAppearance="@style/Toolbar.TitleText"
android:elevation="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
4.In的活動,如下面寫:
Toolbar mytoolbar=(Toolbar)findViewById(R.id.mytoolbar);
setSupportActionBar(mytoolbar);
要自定義您的標題字體:
fontPath = "Fonts/Roboto-Light.ttf";
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), fontPath);
TextView tv_ins=(TextView)FindViewById(R.id.toolbar_title);
tv_ins.setText("mytitle");
tv_ins.setTypeface(tf);
試試這個希望這可以幫助你,如果有什麼不妥,請讓我知道。
這回應我認爲你可以幫助http://stackoverflow.com/a/15181195/2778639 –
@ user27799謝謝,這篇文章解決了我的問題。如果有人遇到類似問題,只需使用鏈接帖子中的方法,該方法與支持庫v-21一起工作良好。 – fragon
解決方案在這裏,[動作條定製設計。] [1] [1]:http://stackoverflow.com/questions/17966350/changing-the-font-of-the-application-title-在android/21480484#21480484 – Karthikeyan