Search code examples
androidactionbarsherlock

Setting a custom text in the center ActionBarSherlock


Is it possible to add a custom text in the center of the Sherlock Action Bar?

I know we can set it on the right like when we add buttons, or next to the logo, but what about in the center of the bar?

EDIT:

I did this, and it renders, but it's just not centered in the bar.

LayoutInflater linflater = (LayoutInflater) getSystemService(getApplicationContext().LAYOUT_INFLATER_SERVICE); 
View GalleryTitleView = linflater.inflate(R.layout.gallery_title_layout, null); 
GalleryTitleTv = (TextView) GalleryTitleView.findViewById(R.id.GalleryTitleTv); 
ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT); 
lp.gravity = Gravity.CENTER_HORIZONTAL; 
GalleryTitleView.setLayoutParams(lp); 
getSupportActionBar().setCustomView(GalleryTitleView); 
getSupportActionBar().setDisplayShowCustomEnabled(true);

Solution

  • Use a custom view with ActionBar.LayoutParams's gravity set to Gravity.CENTER.