Android的API 21工具栏填充 [英] Android API 21 Toolbar Padding
问题描述
我如何摆脱微胖的新工具栏与Android SDK的API版本21(支持库)?
How do I get rid of the extra padding in the new Toolbar with Android SDK API version 21 (the support library)?
我说的是在这张照片中红色箭头:
I am talking about the red arrows on this picture:
下面是code我使用的:
Here is the code I am using:
<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,但仍然围绕微调填充。我做了什么错了还是什么,我需要做的摆脱微胖的?
As you can see I've set all the relevant padding to 0, but there is still padding around the Spinner. What have I done wrong or what do I need to do to get rid of the extra padding?
修改 有人质疑,为什么我试图做到这一点。
Edit Some have questioned why I am trying to do this.
按材质设计规范,微调应该是从左侧的
As per the Material Design specs, the spinner should be 72dp from the left side
我要中和填充谷歌已经以放在那里妥善安置我的微调:
I need to neutralize the padding Google have put there in order to properly place my spinner:
编辑2
根据克里斯·贝恩的回答我下面设置contentInsetStart为0。对于你需要使用的应用程序的命名空间的支持库:
As per Chris Bane's answer below I set the contentInsetStart to 0. For the support library you will need to use the app namespace:
<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>
我希望这可以帮助别人,这让我困惑了好几天。
I hope this helps someone, it had me confused for several days.
推荐答案
左边的插图是由工具栏的 contentInsetStart
默认情况下为16DP造成的。
The left inset is caused by Toolbar's contentInsetStart
which by default is 16dp.
更改为72dp对齐的关键线。
Change this to 72dp to align to the keyline.
这篇关于Android的API 21工具栏填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!