Android toolbar center title and custom font

前端 未结 30 2996
时光说笑
时光说笑 2020-11-22 04:11

I\'m trying to figure out the right way to use a custom font for the toolbar title, and center it in the toolbar (client requirement).

At the moment, i\'m using the

30条回答
  •  一整个雨季
    2020-11-22 05:04

    This's just to help to join all pieces using @MrEngineer13 answer with @Jonik and @Rick Sanchez comments with the right order to help to achieve title centered easly!!

    The layout with TextAppearance.AppCompat.Widget.ActionBar.Title :

        
    
            
    
        
    

    The way to achieve with the right order:

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
    
        setSupportActionBar(toolbar);
        mTitle.setText(toolbar.getTitle());
    
        getSupportActionBar().setDisplayShowTitleEnabled(false);
    

    Please don't forget to upvote @MrEngineer13 answer !!!

    Here is a sample project ToolbarCenterTitleSample

    Hope to help somebody else ;)

提交回复
热议问题