我在Project中实现了自定义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);
答案 0 :(得分:0)
您可以使用以下代码:
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);
}