删除操作栏阴影 [英] Remove action bar shadow

查看:113
本文介绍了删除操作栏阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除出现在appcompat操作栏下方的阴影,以使操作栏的背景完全透明.

I want to remove the shadow that appears below the appcompat action bar so that the background of the action bar is completely transparent.

这是我的主题和操作栏样式:

This is my theme and action bar style:

<resources>

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

    <item name="android:actionBarStyle">@style/TransparentActionBar</item>
    <item name="android:windowActionBarOverlay">true</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/TransparentActionBar</item>
    <item name="windowActionBarOverlay">true</item>

</style>

<!-- Transparent Action Bar Style -->
<style name="TransparentActionBar"
    parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@android:color/transparent</item>

    <!-- Support library compatibility -->
    <item name="background">@android:color/transparent</item>
    <item name="elevation">0dp</item>
</style>

我的最低API级别是16

My minimum API level is 16

我为此尝试了几种解决方案,包括:

I've tried several solutions for this including:

  • 将海拔高度设置为0dp仅适用于棒棒糖设备.
  • 如果我尝试使用windowContentOverlay,则会收到找不到资源"错误
  • 将根视图的背景设置为白色或透明颜色

我一直试图使它在4.4.4上正常工作,但无济于事.低于API级别21不可能吗?

I've been trying to get this to work on 4.4.4 to no avail. Is it not possible below API level 21?

事实证明windowContentOverlay仅适用于android前缀:

it turns out that the windowContentOverlay only works with the android prefix:

<item name="android:windowContentOverlay">@null<item/>

也尝试不使用前缀定义它会导致找不到资源错误(无论出于何种原因,此错误都指向带有前缀的错误).老实说,我不明白为什么会这样.我只能假设appcompat不支持windowContentOverlay属性.

Trying to also define it without the prefix results in the resource not found error (this error points to the one with the prefix for whatever reason). I honestly don't understand why this occurs. I can only assume appcompat doesn't support the windowContentOverlay attribute.

推荐答案

将windowContentOverlay设置为将在操作栏下绘制的可绘制对象.如果您不希望将阴影设置为null,就像这样:

Set windowContentOverlay to a drawable that will be drawn under the action bar. If you don't want a shadow set it to null, like so:

<item name="android:windowContentOverlay">@null</item>

<item name="windowContentOverlay">@null</item>

这适用于API级别16和更高版本.

This works API level 16 and up.

这篇关于删除操作栏阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆