Android:如何删除工具栏和状态栏之间的线

标签 android android-actionbar android-toolbar

我对拥有统一颜色的工具栏和状态栏很感兴趣。如果我提供 colorPrimarycolorPrimaryDark 作为相同的颜色,这应该是可能的。我使用 ActionBar 而不是使用 Toolbar 得到了想要的结果。我还将创建一个导航 View ,因此我需要透明的状态栏。

Using Toolbar Using ActionBar

代码:样式-v21

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

代码:样式

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimary</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

</resources>

重现步骤:

  1. 使用 Navigation Drawer Activity 在 android studio 中创建一个新项目
  2. primaryprimaryDark设置为相同的颜色
  3. 在设备或模拟器上运行

最佳答案

我能想到的唯一解决方案是从 Coordinator Layout 中删除 android:fitsSystemWindows="True"

编辑:另一种解决方案是将协调器布局包装在另一个协调器布局中。

<?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"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay"/>

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


        <include
            layout="@layout/content_main"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

之前 enter image description here

之后 enter image description here

关于Android:如何删除工具栏和状态栏之间的线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33847662/

相关文章:

android - 操作栏未在 4.2.2 中显示

android - 操作栏不显示

带抽屉导航的 Android 中心标题

android - 检测 TextView 是否跨越 2 行

android - 单例使用会在 kotlin 中造成内存泄漏

java - 无法解析符号

android - 修复 CoordinatorLayout 中的底栏

java - InputFilter 内的 IndexOutOfBoundsException

android - 如何在不扩展 AppCompatActivity 的 Activity 中设置工具栏?

安卓 : Unable to hide Toolbar or Action bar