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

前端 未结 3 1430
说谎
说谎 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条回答
  •  猫巷女王i
    2021-01-02 02:48

    How about textAlignment="center"? a RelativeLayout does the trick, when AppCompatTextView has set layout_width="match_parent"; for example:

    
    
    
        
    
            
    
                
                
    
                
    
                    
    
                    
    
                
    
            
    
        
    
    
    

    the down-side is, that when showing several menu-items as action buttons - or when displaying extraordinary long strings as title, the title may overlap them - but when only showing one or two action buttons in combination with a title that fits the visually available width, this works just fine - that's because menu config ifRoom would always apply, because there is room. else one could only measure, which side of the toolbar has the most wide items' container - and then adjust the width on the other side's items' container. scaling the font-size depending on the available room might also be an option, to make it fit dynamically.

提交回复
热议问题