如何使用Android SDK API 21版(支持库)消除新工具栏中的额外填充?

我说的是这张照片上的红色箭头:

以下是我使用的代码:

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:background="?attr/colorPrimary"
        android:padding="0dp"
        android:layout_margin="0dp">

        <RelativeLayout
            android:id="@+id/action_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="0dp"
            android:padding="0dp"
            android:background="#000000">

            <Spinner
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        </RelativeLayout>
</Toolbar>

正如你所见,我已经将所有相关的填充设置为0,但微调器周围仍然有填充.我做错了什么,或者我需要做什么来go 除多余的填充物?

Edit

根据material 设计规范,旋转器从左侧开始应为72dpdesc

我需要中和谷歌放在那里的填充物,以便正确放置微调器:desc

Edit 2

根据Chris Bane下面的回答,我将ContentInsertStart设置为0.对于支持库,您需要使用应用程序名称空间:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

     <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="@dimen/action_bar_height"
        android:background="?attr/colorPrimary"
        android:contentInsetStart="0dp"
        android:contentInsetLeft="0dp"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

</android.support.v4.widget.DrawerLayout>

我希望这能帮助别人,这让我困惑了好几天.

推荐答案

左边的插图是由工具栏的contentInsetStart引起的,默认为16dp.

将其更改为72dp以与按键对齐.

Update for support library v24.0.0:

为了匹配material 设计规范,还有一个额外的属性contentInsetStartWithNavigation,默认值为16dp.如果您还有导航图标,请更改此选项.

Android相关问答推荐

具有数据类的LiveData不会在视图模型中更新

时区日光节约改变问题

Android使用参数编写齐射后请求

RippleTheme在作曲material 1.7.0中被废弃

Jetpack Compose make父级图像填充高度

理解修饰符<;方法>;与修饰符<;方法>;:效果和行为解释(Android开发者Jetpack Compose)

Jetpack Compose-如何使用值动画直接控制其他动画

Android和Rust,OpenSSL交叉编译在ARM V7上链接失败

从单元测试访问RES/RAW文件

Android Kotlin ImageView内置于Kotlin ImageView中.适配器未按预期更新

如何使用进度条和返回函数进行API调用,同时在Android上使用Kotlin保持高效?

如何共享没有';t是否存在?(仅信息)在Android?

了解 CoroutineScope(Job() + Dispatchers.Main) 语法

修复报错 RecyclerView: No adapter attached;跳过布局

如何删除房间数据库?

Jetpack Compose 如何使一个项目相对于另一个项目垂直居中

如何将一个 Composable 作为其参数传递给另一个 Composable 并在 Jetpack Compose 中显示/运行它

如何使用底页,启用和展开父交互

jetpack compose 中的可点击指示是什么?

不能在kotlin的lazycolumn中使用列表