首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android API 21工具栏填充

Android API 21工具栏填充
EN

Stack Overflow用户
提问于 2014-10-20 04:25:17
回答 10查看 104.5K关注 0票数 202

如何在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,但是微调器周围仍然有填充。我做错了什么,或者我需要做些什么来消除额外的填充?

编辑有些人质疑我为什么要这样做。

根据材质设计规范,微调器应该是从左侧算起的72dp

我需要中和Google放在那里的填充,以便正确地放置我的旋转器:

编辑2

根据Chris Bane下面的回答,我将contentInsetStart设置为0。对于支持库,您需要使用app命名空间:

<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>

我希望这对某些人有帮助,它让我困惑了好几天。

EN

回答 10

Stack Overflow用户

回答已采纳

发布于 2014-10-22 04:42:14

左边的插图是由Toolbar的contentInsetStart引起的,默认情况下是16dp。

将其更改为72dp,以与关键字线对齐。

支持库v24.0.0的更新:

为了匹配材料设计规范,还有一个额外的属性contentInsetStartWithNavigation,默认情况下是16dp。如果您还有导航图标,请更改此设置。

票数 290
EN

Stack Overflow用户

发布于 2014-12-05 13:41:16

上面的答案是正确的,但仍然有一件事可能会产生问题(至少它确实给我带来了一个问题)

我使用了以下方法,但它在旧设备上不能正常工作-

android:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"

这里的诀窍就是使用下面的代码-

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"

去掉-

android:contentInsetStart="0dp"
android:contentInsetLeft="0dp"

现在,它应该可以在所有设备上正常工作。

希望能有所帮助。

票数 147
EN

Stack Overflow用户

发布于 2017-01-02 14:08:47

简单地在工具栏中添加这两行。然后我们得到新的删除左侧空格bcoz,默认情况下是16dp。

android:contentInsetStart="0dp"
app:contentInsetStart="0dp"
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26455027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档