【问题标题】:Changing the text on action bar custom view [duplicate]更改操作栏自定义视图上的文本 [重复]
【发布时间】:2014-08-19 11:07:51
【问题描述】:

我在我的项目中实现了自定义 actionBar。它有两个 Textview 我想以编程方式更改文本如何做到这一点。我尝试了以下代码,但我的操作栏没有变化

    this.getActionBar().setDisplayShowCustomEnabled(true);
    this.getActionBar().setDisplayShowTitleEnabled(false);
    this.getActionBar().setDisplayUseLogoEnabled(false);
    this.getActionBar().setDisplayHomeAsUpEnabled(false);
    this.getActionBar().setDisplayShowHomeEnabled(false);
    this.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

    LayoutInflater inflator = LayoutInflater.from(this);

    View v = inflator.inflate(R.layout.actionbarlayout, null);
    mSiteName= ((TextView)v.findViewById(R.id.sitenameastitle));

    mSiteName.setText("helloooo");

    this.getActionBar().setCustomView(v);

【问题讨论】:

  • 你应该在提问之前先做一些搜索,但只是为了第一次推送,我在下面给出了一个代码。

标签: android custom-component android-actionbar-compat


【解决方案1】:

您可以使用以下代码:

public void ActivityName(String name)
{
    ActionBar actionBar = getSupportActionBar();

    LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View activityName = inflator.inflate(R.layout.actionbar_title_view, null);

    ((TextView) activityName.findViewById(R.id.actionbar_title)).setText(name);

    Typeface robotoBoldCondensedItalic = Typeface.createFromAsset(getAssets(), "fonts/bisque.ttf");

    ((TextView) activityName.findViewById(R.id.actionbar_title)).setTypeface(robotoBoldCondensedItalic);

    actionBar.setCustomView(activityName);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 2013-12-04
    • 1970-01-01
    • 2012-08-10
    • 1970-01-01
    相关资源
    最近更新 更多