![](/img/trans.png)
[英]How to align menu item to center_vertical after changed the height of toolbar
[英]center align the toolbar items when height of toolbar is changed
我正在嘗試降低工具欄的高度,但是當我聲明工具欄內的特定高度項目時,其格式未居中。如何在我的案例中居中排列以下是我的完整詳細信息
Toolbar.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_gravity="center"
android:gravity="center"
android:background="#414e5b"
/>
</LinearLayout>
Themes.xml
<style name="Orange" parent="Theme.AppCompat.Light.NoActionBar">
----------------
<item name="actionButtonStyle">@style/ActionButtonStyle</item>
------------------
</style>
<style name="ActionButtonStyle" parent="Widget.AppCompat.ActionButton">
<item name="android:minWidth">0dip</item>
<item name="android:maxWidth">40dip</item>
<item name="android:paddingLeft">0dip</item>
</style>
請嘗試下面的xml代碼創建Toolbar
。 這使您可以將工具欄置於centre
位置:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_centerInParent="true"
android:background="#414e5b"
/>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.