更改自定义动作条标题 [英] Change custom actionbar title

查看:135
本文介绍了更改自定义动作条标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是自定义布局居中actiobar的称号。

I'm using a custom layout to center the title of the actiobar.

  ActionBar actionBar = getActionBar(); 
  actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  actionBar.setCustomView(R.layout.action_bar);

在这里action_bar是一个TextView一个简单的线性布局

where action_bar is a simple linear layout with a textview

我的问题是,我需要每一个活动,有不同的名称 - ,我需要以编程方式更改主题。所以我想是这样的:

My problem is that I need every activity to have different names - and I need to change theme programmatically. So I'm trying something like this:

private void setActiobarTitle(String title)
{
   LayoutInflater inflator  = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   View v = inflator.inflate(R.layout.action_bar, null);
   TextView titleTxtView = (TextView) v.findViewById(R.id.actionbarTitle);
   titleTxtView.setText(title);
}

在debuging TextView的是发现和初始化,一切似乎是好的 - 但标题不会改变。 谁能告诉我什么,似乎是这个问题?

When debuging the textview is found and initialized and everything seems to be okay - but the title doesn't change. Can anyone please tell me what seems to be the problem?

推荐答案

修改setActionbarTitle(),如下

Modify the setActionbarTitle() as below

 private void setActiobarTitle(String title)
 {

    View v = getActionbar().getCustomView();
    TextView titleTxtView = (TextView) v.findViewById(R.id.actionbarTitle);
    titleTxtView.setText(title);
 }

这篇关于更改自定义动作条标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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