android - 如何使用 String.format 创建格式化标题

标签 android android-actionbar

我找到了 this question ,而且效果很好。但是我有一个资源字符串,它是一个进入 String.format 的格式字符串。 .

考虑 R.string.test成为This is a test: <b>%1$s</b> .

然后这段代码:

getActionBar().setTitle(String.format(getString(R.string.test), "TEST"));

不显示粗体,但这样做(但它没有明显显示替换的字符串):

getActionBar().setTitle(getResources().getText(R.string.test));

如何使用 String.format创建格式化标题?

最佳答案

你试过Html.fromHtml吗:

getActionBar().setTitle(Html.fromHtml("<font color=#343434>" + "Your Text" + "</font>"));

我还有一个,这是一个有多个空格的 Html 字符串:

getActionBar().setTitle(Html.fromHtml("<font color=#FFFFFF>" + "&nbsp&nbsp&nbsp&nbsp&nbsp" +"Your Text" + "</font>"));

你也可以直接去:

setTitle(Html.fromHtml("<font color=#343434>" + "Your Text" + "</font>"));

enter image description here

关于android - 如何使用 String.format 创建格式化标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37392885/

相关文章:

android - 如何获取 Webview iframe 链接以启动浏览器?

Android Drawable 根据设备屏幕尺寸变化

android - ActionBar 列表导航 : different text color in header and pop up menu

Android Swipe Tab Action Bar - 使选项卡中的更改持久化

android - sub3.0 设备上的 ActionBar - 使用我的自定义系统实现 ActionBarSherlock?

android - 设置 Android PreferenceFragment 的正确方法是什么?

android - 如何防止在 Fragment 内重新创建/重新加载 MapView?

android - 如何从 key.pk8 和 certificate.pem 生成 Android Keystore?

android - kotlin + 改造 + 协程 + androidTest

android - 如何使android操作栏标题居中对齐?