17

我使用工具欄的新方法存在問題。在橫向模式下,工具欄標題垂直居中,但導航抽屜不是。我該如何解決這個問題?導航抽屜圖標不是垂直居中(風景模式,Android)

我在這個崗位克里斯詛咒的使用工具欄,如: AppCompat v21 — Material Design for Pre-Lollipop Devices!

這是在style.xml抽屜圖標代碼:

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle"> 
    <item name="spinBars">true</item> 
    <item name="color">@android:color/white</item> 
</style> 

這是的圖像問題: Landscape image

編輯:溢出按鈕沒有垂直居中太...

回答

29

這是我的工具欄的主題,一切都正確中心:

<android.support.v7.widget.Toolbar 
    android:layout_width="match_parent" 
    android:layout_height="?actionBarSize" 
    style="@style/Widget.MyApp.Toolbar"> 

</android.support.v7.widget.Toolbar> 

的例子說,使用android:minHeight="?actionBarSize"android:_layout_height="wrap_content",但只生產了您所描述的錯誤。

+0

非常感謝,它工作正常! – Dahnark 2015-01-21 12:30:03

+0

在我的情況下,這很好地集中了一切,但由於某種原因,它會在設備旋轉時改變工具欄的高度(由於某些原因,它在橫向上更短)。所以在視覺上,這是一個可行的解決方案。 – GaryAmundson 2015-01-31 16:05:11

+0

是的,規格說明手機上的操作欄總是56dp。但規格說謊。它實際上是以48dp的格式實現的。這是設計和正確的,最終空間有限。 – 2015-01-31 16:08:31

6

在工具欄風格補充一點:

<item name="maxButtonHeight">?attr/actionBarSize</item> 

這允許您使用WRAP_CONTENT高度,仍然有一箇中心的圖標!

+0

這是一個更好的解決方案,它不會剪切工具欄的字幕。也可以在xml'app:maxButtonHeight =「?attr/actionBarSize」'中完成 – behelit 2017-02-23 22:22:13