我找到了 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>" + "     " +"Your Text" + "</font>"));
你也可以直接去:
setTitle(Html.fromHtml("<font color=#343434>" + "Your Text" + "</font>"));
关于android - 如何使用 String.format 创建格式化标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37392885/