-2

Hey all It may be asked several time before but I want to set text middle to a Action Bar I have used following code to get that done..it doesn't help..

ActionBar bar = getActionBar();

bar.setTitle(Html.fromHtml("<center>" + "<b>" + "Sign Up" + "</b>"
                + "</center>"));

bu when I use   then my purpose is fulfilled any accurate answer.

Rituraj suman
  • 216
  • 1
  • 16
  • Please give answer before you vote down. – Rituraj suman Jan 07 '15 at 10:35
  • 3
    "It may be asked several time" : it has been, so why didn't you refer to those questions ? A simple Google search will returns dozens so why add a new one ? – 2Dee Jan 07 '15 at 10:35
  • I said may be..i am not sure about that...and i tried code i already shared so please may you check where i am wrong – Rituraj suman Jan 07 '15 at 10:37
  • 1
    the title textview is not full width of action bar, and it is not placed on middle of actionbar. to place title in center, you have to create custom actionbar layout – calvinfly Jan 07 '15 at 10:41

1 Answers1

1
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("Your centered text");
getSupportActionBar().setCustomView(customView, params);