android - 如何在操作栏中设置字体?

标签 android android-actionbar typeface

<分区>

我有一个 Activity 从其他 Activity 的 ListView 位置获取 ActionBar 标题,我想设置 TypefaceActionBar 中。

package com.cambobox.actionbartitle.actionbar;

import android.app.ActionBar;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.TypefaceSpan;
import android.widget.TextView;

public class Song extends ActionBarActivity {
Typeface font;
@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_song);
   font = Typeface.createFromAsset(getAssets(),"fonts/khmerbibleregular.ttf");
   Intent intent = getIntent();
   String listview_id = intent.getStringExtra(SongList.NAME);
   ActionBar actionnbar_title = getActionBar();
   actionnbar_title.setDisplayShowTitleEnabled(true);
   actionnbar_title.setTitle(font);
   actionnbar_title.setTitle(listview_id);
}
}

最佳答案

虽然有点乱,但确实有效。

protected void onCreate(Bundle savedInstanceState) {
    ...
    int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
    TextView textView = (TextView) findViewById(titleId);
    Typeface typeface = Typeface.create("sans-serif-light", Typeface.ITALIC); // add your typeface
    textView.setTypeface(typeface);
    ...
}

关于android - 如何在操作栏中设置字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24033299/

相关文章:

android 我想要这样的操作栏

android - 如何使用 InputStream 加载字体

android - 对具有 HTL 格式的相同 TextView 使用不同的字体

android - 如何在 Android 中解析 JSON 对象

android - 尽管有 configChanges 设置,onDestroy 在轮换时被调用

android - Android 中 ListView 的 setBackgroundDrawable

android - 如何在删除 SQLite 数据库中的行后更新 KEY_ROWID

android - 隐藏启动画面的操作栏

Android 搜索 View : Open suggestions list dropdown by default

android - TextView 的高度和宽度没有改变?