【问题标题】:toolbar overlays status bar工具栏覆盖状态栏
【发布时间】:2015-11-29 14:25:36
【问题描述】:

我正在尝试通过使用使状态栏透明
真的 状态栏显示透明,但问题是工具栏覆盖在状态栏上。工具栏是半可见的,位于状态栏后面。我用 true 解决了这个问题 但状态栏显示为灰色,而不是我设置的原色。怎么了??

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

    <item name="colorPrimary">@color/primary_500</item>
    <item name="colorPrimaryDark">@color/primary_700</item>

    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:fitsSystemWindows">true</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowTranslucentStatus">true</item>

</style>

这是我的主题

【问题讨论】:

    标签: java android statusbar transparent


    【解决方案1】:

    这是因为你还指定了&lt;item name="android:fitsSystemWindows"&gt;true&lt;/item&gt;,告诉Android你想自己处理系统UI(比如状态栏)。

    如果您删除该元素,您应该会发现您的工具栏位于状态栏下方。

    如果出于某种原因,您需要更新布局以实际考虑状态栏。

    【讨论】:

    • @Tanis--- 如果我删除 true,那么工具栏不会出现在状态栏
    • 您是否也碰巧使用了 CollapsingToolbarLayout?如果是这样,您可能正在寻找这个问题:stackoverflow.com/questions/30882429/…
    • 或者您可能在其他地方的布局中使用fitsSystemWindows - 检查它的任何其他用法。
    • 不,它只是一个工具栏和导航视图
    【解决方案2】:

    请在此链接查看我已经回答了类似的问题此外您可以将状态栏颜色设置为透明

    How to remove this gray color from topbar/status bar

    【讨论】:

    • 移除这个 truetrue 有助于移除灰色。但我想让状态栏在导航抽屉上透明。可以使用 true 来实现这只是对吗??
    【解决方案3】:

    在 Styles-v21 中添加尺寸为 25dp,在样式中为 0dp 您必须添加额外的布局,将该尺寸作为工具栏上方的高度并使用所需的颜色。

    我的 Styles.xml

    <style name="AppTheme.MovieDetails" parent="AppTheme.Base">
            <!-- Customize your theme here. -->
    
            <item name="android:textColorPrimary">@android:color/white</item>
            <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
            <item name="android:windowTranslucentStatus" tools:targetApi="21">true</item>
            <item name="android:windowContentOverlay">@null</item>
    
            <!-- Toolbar Theme / Apply background_with_ripple arrow -->
            <item name="colorControlNormal">@android:color/white</item>
            <item name="actionBarTheme">@style/AppTheme.ActionBarTheme</item>
    
            <!-- Material Theme -->
            <item name="android:navigationBarColor" tools:targetApi="21">@color/navigationBarColor
            </item>
            <item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="21">true</item>
        </style>
    

    【讨论】:

    • verma........ 有必要加padding吗??因为我在其他应用程序中看到过,这也是在没有填充的情况下实现的。
    • 是的添加填充我将添加我的styles.xml评论检查它
    • 什么是AppTheme.ActionBarTheme?它不存在。
    • 这是我自己的主题,你可以删除,写你自己的风格
    猜你喜欢
    • 1970-01-01
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-08
    • 2016-12-21
    • 1970-01-01
    • 2017-05-10
    相关资源
    最近更新 更多