在Android工具栏中删除汉堡包(菜单)图标后的大填充?

Dav*_*uez 23 android android-toolbar

这是菜单图标后面的大填充间隙的图片: 在此输入图像描述

这是在我的项目没有工作一个月(暑期学校)后发生的.我刚刚回到它并注意到在我更新Android Studio后工具栏上的这个差距比正常大.我在SO上找不到任何关于此的问题/解决方案.如果有人能提供帮助,那将非常感激.

我通过这样做加载汉堡包图标(每行都正确放置在应用程序中,在类声明,onCreate()等中.为了简单起见,我把它放在这里.):

ActionBarDrawerToggle mDrawerToggle;
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), dl, toolbar, R.string.nav_open, R.string.nav_closed)
mDrawerToggle.syncState();
Run Code Online (Sandbox Code Playgroud)

这是我的工具栏的xml代码:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:minHeight="?attr/actionBarSize"
    app:layout_scrollFlags="scroll|enterAlways"
    app:title="Test Title">

</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)

我尝试搞乱各种contentInsetxml属性但没有影响菜单图标后的间距.

编辑:此链接显示我曾经拥有的(在页面中间找到).如果您注意到标题和汉堡包图标之间的间距,则间距不会像此处显示的图片那样宽.这就好像间距增加了一倍.

Dav*_*uez 53

我想到了!我必须设置

app:contentInsetStartWithNavigation="0dp"

在我的Toolbar布局中.

在此输入图像描述

  • 根据以下内容,我们在支持库24.0.0+中引入了这个新的填充:https://code.google.com/p/android/issues/detail?id = 213826 (3认同)
  • 谢谢!我们也可以用编程方式`toolbar.setContentInsetStartWithNavigation(0);` (3认同)
  • app:contentInsetLeft ="0dp"app:contentInsetStart ="0dp"app:contentInsetStartWithNavigation ="0dp" (2认同)

blu*_*are 16

将这些属性添加到您的Toolbar:

app:contentInsetLeft="0dp" 
app:contentInsetStart="0dp" 
app:contentInsetStartWithNavigation="0dp"
Run Code Online (Sandbox Code Playgroud)

这将禁用Toolbar标题中的插入开始填充