ListActivity中标题栏中的Android自定义字体

标签 android listactivity titlebar

我正在解决这个问题。我需要在标题栏中设置自定义字体,但我的 Activity 正在使用动态生成的布局(因此未使用 setContentView(R.layout.somtehing))。

我已经尝试过,要在标题栏中设置自定义字体,您可以通过以下代码来实现:

    type = Typeface.createFromAsset(getAssets(),"fonts/verdanab.ttf");
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.something);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.gal_title);

    title = (TextView) findViewById(R.id.title);
    title.setText(R.string.Text);
    title.setTypeface(type);

问题是,这段代码不起作用,应用程序看不到 TextView 标题,因为没有 setContentView()。有什么建议吗?

谢谢

最佳答案

在这一行之后初始化这一行 type = Typeface.createFromAsset(getAssets(),"fonts/verdanab.ttf");

 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.gal_title);

使用这段代码,

 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.something);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.gal_title);

    Typeface  type = Typeface.createFromAsset(getAssets(),"fonts/verdanab.ttf");
    title = (TextView) findViewById(R.id.title);
    title.setText(R.string.Text);
    title.setTypeface(type);

关于ListActivity中标题栏中的Android自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11684204/

相关文章:

android - 更改 ListActivity 的托管游标的正确方法是什么

android - ArrayAdapter.setNotifyOnChange 工作不正常

android - 删除元素后如何刷新数组列表?

javascript - 书签标题

android - 类似于 Youtube 应用程序的标题栏

android - 为什么在添加对 x86 的支持后我只添加了 4 个新设备?

android - VLC 实时 http 流式传输到 Android

android - 一段时间不活动后应用程序响应异常

android - Match_parent 属性的用途

Android - FEATURE_NO_TITLE 不起作用