How to set the ActionBar title in middle instead of the default left aligned position?

前端 未结 5 948
予麋鹿
予麋鹿 2020-12-07 05:28

Trying to set the ActionBar title in middle instead of the default left aligned position. To do so, based on other answers this is what I\'ve done:



        
5条回答
  •  自闭症患者
    2020-12-07 06:14

    Simple approach use android:layout_gravity="center" on your TextView and hide default title using below code after that initialize your TextView and set value

    Inside your activity:

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    toolbar_title = (TextView) findViewById(R.id.toolbar_title);
    toolbar_title.setText("My Custom center title");
    

    Custom toolbar XML Code:

    
    
    
        
    
    
    

提交回复
热议问题