Android 工具栏边距
Android Toolbar Margin
我对 android 工具栏有疑问。通常,工具栏从左到右填满整个 space,顶部没有边距。
我的看起来像一块瓷砖,到处都有边距。 Android Studio 渲染得很好,但是当我在 Galaxy Tab 4 上 运行 它时,它看起来像一个瓷砖。
截图
Activity:
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>
好的,错误在 activity 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>
我对 android 工具栏有疑问。通常,工具栏从左到右填满整个 space,顶部没有边距。
我的看起来像一块瓷砖,到处都有边距。 Android Studio 渲染得很好,但是当我在 Galaxy Tab 4 上 运行 它时,它看起来像一个瓷砖。
截图
Activity:
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>
好的,错误在 activity 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>