栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在ActionBar标题中设置自定义字体?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在ActionBar标题中设置自定义字体?

我同意不完全支持此操作,但这就是我所做的。您可以将自定义视图用于操作栏(它将显示在图标和操作项之间)。我正在使用自定义视图,并且已禁用本机标题。我所有的活动都继承自一个活动,该活动在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 actionbarthis.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>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/431271.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号