Android工具栏保证金

时间:2015-08-10 21:32:10

标签: android margin padding toolbar

我对android工具栏有疑问。通常,工具栏从左到右填充整个空间,并且顶部没有边距。

我看起来像瓷砖,到处都有边距。 Android Studio渲染效果很好,但是当我在Galaxy Tab 4上运行时,它看起来就像是一块瓷砖。

截图

enter image description here

的活动:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_newsreader);

    // create the toolbar
    toolbar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

app_bar.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbarxmlns: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="wrap_content"
android:background="@color/primary"
app:popupTheme="@style/CustomToolbarPopup"
app:theme="@style/CustomToolbarTheme"
app:navigationIcon="@drawable/ic_home_white_16dp">
</android.support.v7.widget.Toolbar>

styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/primary</item>
    <item name="android:textColorPrimary">@color/primary_text</item>
    <item name="android:textColorSecondary">@color/secondary_text</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="actionModeBackground">@android:color/black</item>
</style>


<!-- -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
</style>
<!---->
<style name="CustomToolbarTheme" parent="Base.ThemeOverlay.AppCompat.Dark">
    <item name="android:textColorPrimary">@color/toolbar_text</item>
    <item name="windowActionModeOverlay">true</item>
</style>

<style name="CustomToolbarPopup" parent="Base.ThemeOverlay.AppCompat.Light">
</style>

1 个答案:

答案 0 :(得分:2)

好的,错误在活动xml中,其中LinearLayout的填充设置为 5dp

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:animateLayoutChanges="true"
  android:descendantFocusability="beforeDescendants"
  android:focusableInTouchMode="true"
  android:orientation="vertical"
  android:padding="5dp">

      <include
    android:id="@+id/app_bar"
    layout="@layout/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

      </include>