【问题标题】:Making the statusbar have a color, yet be transparent使状态栏有颜色,但透明
【发布时间】:2015-10-28 14:48:26
【问题描述】:

这是我当前的布局:

生成这个的 xml 文件如下所示:

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            style="@style/toolbarTheme"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"/>
    </LinearLayout>

    <include layout="@layout/drawer"/>
</android.support.v4.widget.DrawerLayout>

主题使用的样式:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:colorPrimary">@color/primary</item>
        <item name="android:colorPrimaryDark">@color/primary_dark</item>
        <item name="android:colorAccent">@color/accent</item>
        <item name="android:statusBarColor">@color/primary_dark</item>
        <item name="android:windowTranslucentStatus">true</item>
</style>

预期的结果是状态栏将以 primary_dark 颜色着色,但抽屉应该在它的顶部(就像在 Google 应用程序中一样),但我得到了这个结果。我该如何解决这个问题?

【问题讨论】:

    标签: android xml material-design statusbar


    【解决方案1】:

    您需要确保您的活动具有android:fitsSystemWindows="true"android:clipToPadding="true",但请记住,这仅适用于更高版本的 android

    【讨论】:

    • android:fitsSystemWindows="true" 已在 LinearLayout 上设置,如果我将其设置在其他任何地方,工具栏(实际上是整个应用程序)似乎位于状态栏下方
    • @tofiffe 尝试删除此&lt;item name="android:windowTranslucentStatus"&gt;true&lt;/item&gt; 或将其设为假
    • 如果我这样做,抽屉将不再绘制在状态栏上的图标下方
    • @tofiffe 这不符合设计指南吗? google.co.in/design/spec/patterns/navigation-drawer.html
    • 我的意图是尽可能接近谷歌应用,其中抽屉被绘制在状态栏下方,状态栏仍然具有定义的颜色
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-13
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    • 2015-10-01
    • 2018-08-12
    相关资源
    最近更新 更多