Is there an official API for centered title on Toolbar like on popular Android apps, in the new material design?

前端 未结 3 1438
说谎
说谎 2021-01-02 02:00

Background

In the past, Google always shown the toolbar to have the title aligned to the left:

https://material.io/develop/android/components/app-bar-layou

3条回答
  •  没有蜡笔的小新
    2021-01-02 02:35

    TL;DR: No, there's currently no official way to center the title on a toolbar.


    I don't think there is an official way to do it, at least not yet. But I know that the Flutter framework supports it and it's pretty straight forward: you simply need to pass centerTitle: true to the appbar constructor, as described in this answer. And there's a good chance that the apps you've mentioned in your question were built with Flutter, since both are from Google.

    I think the closest workaround to your expected layout is having the TextView on top of the Toolbar, as shown here:

    
        
    
            
            
    
            
    
        
    
    

    But it would be really nice if the official Android API could support this the same way flutter does. Maybe you'd like to send a feature request to the Material Components Android Issue Tracker?

提交回复
热议问题