无法格式化操作栏标题 [英] Can't format action bar Title

查看:97
本文介绍了无法格式化操作栏标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常简单的问题,但目前我无法对其进行排序.

This is probably a really simple question to answer but at the moment I can't sort it.

我的操作设置如下:

// get action bar
ActionBar actionBar = getSupportActionBar();

// set up the action bar layout
final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.actionbar_layout,null);

// apply layout
actionBar.setCustomView(actionBarLayout);

我尝试按如下所示设置操作栏标题:

I have tried to set up the action bar title as follows:

  // setting action bar title
  actionBar.setTitle(getResources().getString(R.string.testing_title));

可以正确应用标题,问题是在字符串文件中将testing_title的格式设置为:

That applies the title correctly, the problem is testing_title is formatted in the strings file as follows:

 <string name = "testing_title"><b>Testing</b>Testing</string>

因此,第一个测试"应为粗体,第二个为正常.问题是,两者都不大胆.有人知道我应该在这里做什么吗?

So the first 'Testing' should be bold and the second normal. The problem is that neither are emboldened. Would anyone know what I should do here?

在操作栏自定义布局中,我有一个用于显示标题的文本视图,并在此处找到类似于以下内容的答案:

In my action bar custom layout I had a text view which I was using to display the title and found an answer on here similar to this:

  private void setActionBarTitle(String title, ActionBar ab)
    {
        View v = ab.getCustomView();
        TextView titleTxtView = (TextView) v.findViewById(R.id.actionBarTitle);
        titleTxtView.setText(title);
    }

然后我这样称呼它:

setActionBarTitle(getResources().getString(R.string.audioWalks_title), actionBar);

但是,这没有产生任何结果. 如果有人可以提供任何帮助,我将不胜感激.

This however didn't produce any results. If anyone could be on any help I'd appreciate it.

推荐答案

错误必须在这里

// setting action bar title
actionBar.setTitle(getResources().getString(R.string.testing_title));

java.lang.String不能包含范围.尝试获取CharSequence参考.

The java.lang.String can't contain spans. Try getting the CharSequence reference.

actionBar.setTitle(getResources().getText(R.string.testing_title));

这篇关于无法格式化操作栏标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆