Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 汉堡图标和标题未正确对齐_Java_Android_Xml - Fatal编程技术网

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>