アセットフォルダ内のフォントを使用して、(可能であれば)ActionBarタイトルテキスト(タブテキストのみ)にカスタムフォントを設定するにはどうすればよいですか?android:logoオプションを使いたくありません。
これが完全にサポートされていないことに同意しますが、これが私がしたことです。アクションバーにカスタムビューを使用できます(アイコンとアクションアイテムの間に表示されます)。カスタムビューを使用していて、ネイティブタイトルを無効にしています。私のすべてのアクティビティは、onCreateに次のコードがある単一のアクティビティから継承します。
this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);
LayoutInflater inflator = LayoutInflater.from(this);
View v = inflator.inflate(R.layout.titleview, null);
//if you need to customize anything else about the text, do it here.
//I'm using a custom TextView with a custom font in my layout xml so all I need to do is set title
((TextView)v.findViewById(R.id.title)).setText(this.getTitle());
//assign the view to the actionbar
this.getActionBar().setCustomView(v);
そして、私のレイアウトxml(上記のコードのR.layout.titleview)は次のようになります。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent" >
<com.your.package.CustomTextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:textSize="20dp"
android:maxLines="1"
android:ellipsize="end"
android:text="" />
</RelativeLayout>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加