Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align center the title or label in activity?

I know there are two ways of setting the title of activity. One way is the setting it in the android manifest like this android:label="@string/app_name". Second is programmatically setting in activity class like setTitle("Hello World!"). Both ways are positioned in the left side but how can I put it in the center?

like image 496
iamtheexp01 Avatar asked Mar 18 '11 02:03

iamtheexp01


1 Answers

It will work fine..

TextView customView = (TextView) 
LayoutInflater.from(this).inflate(R.layout.actionbar_custom_title_view_centered, 
     null); 

ActionBar.LayoutParams params = new ActionBar.LayoutParams(
     ActionBar.LayoutParams.MATCH_PARENT, 
     ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER ); 

customView.setText("Some centered text"); 
getSupportActionBar().setCustomView(customView, params); 
like image 103
Chaitu Avatar answered Oct 03 '22 15:10

Chaitu