Toolbar title not in center when Back Button is enable

前端 未结 6 671
名媛妹妹
名媛妹妹 2021-02-02 13:53

I\'m trying to display my toolbar title in the center and to do it I use the method which is given in this answer :-Toolbar Center title

However, when I enable back butt

6条回答
  •  长发绾君心
    2021-02-02 14:16

    The reason why the title is not centered when you use a back button as navigation icon, is that navigation icon is represented as AppCompatImageButton and is added to the same layout as your title TextView. Using Arshak's answer is not a bad idea, but ?android:attr/actionBarSize is not a good way to define the end margin. As the action bar height is probably the same size as icon's width, it might work, but might not work on all devices. Could be a good idea to specify this size from material design guidelines.

提交回复
热议问题