I'm using toolbar from support library in my project. And I can't find how to change text alignment. It is at left on default. But I need to move it to the center. I think there is a method setTitleTextAppearance() for it but I don't understand its using.
            Asked
            
        
        
            Active
            
        
            Viewed 9,990 times
        
    2
            
            
        - 
                    http://stackoverflow.com/questions/26439715/android-how-to-style-action-bar-with-pattern/26441088#26441088 – codePG Nov 21 '14 at 06:41
 - 
                    u can customize your toolbar – Ando Masahashi Nov 21 '14 at 06:45
 - 
                    kindly refer : http://stackoverflow.com/questions/18418635/how-to-align-title-at-center-of-actionbar-in-default-themetheme-holo-light – Sivakumar Nov 21 '14 at 06:55
 - 
                    @codePG, I have tried it, but as I know, toolbar is not standart actionbar and this method isn't work correctly. – Bringoff Nov 21 '14 at 07:02
 
2 Answers
4
            
            
        Add your own TextView which can be aligned wherever you want:
<android.support.v7.widget.Toolbar
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/toolbar"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="@color/green">
   <!-- Below will add your text in the center of the toolbar -->
   <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Your Text"
    android:textColor="#ff0000"
    android:textStyle="bold"/>
 </android.support.v7.widget.Toolbar> 
        Mohi
        
- 1,776
 - 1
 - 26
 - 39
 
        Abhinav Puri
        
- 4,254
 - 1
 - 16
 - 28
 
0
            
            
        It's quite easy - you can do it programmatically:
    public class AboutUsActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_us);
        Toolbar toolbar = (Toolbar) findViewById(R.id.devtoolbar_about);
        toolbar.setTitle("About Us");
        toolbar.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
        setSupportActionBar(toolbar);
    }
}
The options for alignment are: TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_LEFT, and others. PS: I know this is an old question!