Java 汉堡图标和标题未正确对齐
我目前正试图在工具栏上添加一个汉堡图标,但似乎标题和图标没有正确对齐,图标位于标题所在的中心上方一点Java 汉堡图标和标题未正确对齐,java,android,xml,Java,Android,Xml,我目前正试图在工具栏上添加一个汉堡图标,但似乎标题和图标没有正确对齐,图标位于标题所在的中心上方一点 <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app1="http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app1="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:elevation="6dp"
android:background="?attr/colorPrimary"
app1:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:contentInsetStart="72dp"
app1:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
这是我的工具栏,我尝试应用我在一些博客上看到的一种风格来修复它,这就是它的样子(没有它,情况更糟)
48dp
中心垂直
16dp
72dp
50dp
通过以下方式添加汉堡图标:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
通过以下方式添加标题:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarId"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<TextView
android:id="@+id/toolbarTitleId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="20sp" />
</android.support.v7.widget.Toolbar>
您可以通过android:gravity=“preference position”
在工具栏中设置标题的位置
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarId"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<TextView
android:id="@+id/toolbarTitleId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="20sp" />
</android.support.v7.widget.Toolbar>