繁体   English   中英

如何在Android中从工具栏删除空间

[英]How to remove space from Tool bar in android

我正在开发一个Android应用程序,在其中我需要使Status barToolbar透明。

如何删除Toolbar以红线突出显示的左右空间?

我这样做如下:

main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:openDrawer="start">

    <include
        layout="@layout/action_bar_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/main_activity_drawer" />

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

并且action_bar_main.xml是:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="de.slowpoke.android.news.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/newsAppToolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#51000000"
            android:clickable="false" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>

使用的样式如下:

<style name="AppTheme.NoActionBar" parent="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:statusBarColor">#51000000</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

在此处输入图片说明

那是因为:

<item name="android:statusBarColor">#51000000</item>

您已经拥有:

android:background="#51000000"

作为Toolbarbackground

您可能还想使用此:

android:layout_height="?actionBarSize"

代替:

android:layout_height="wrap_content"

还有一点,该Toolbar不应该存在,您应该将其与一起使用:

<item name="colorPrimaryDark">@color/colorPrimaryDark</item>

用于StatusBar颜色。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM