我使用 Developer Guide启用 ActionBar 覆盖,但不起作用
action bar不透明,布局在ActionBar下方
预期:
风格
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/CustomActionBarTheme</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/CustomActionBarTheme</item>
</style>
<style name="CustomActionBarTheme" parent="Theme.AppCompat">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
主要布局
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#AABBCC"
tools:context=".MainActivity">
</RelativeLayout>
最佳答案
您需要将 Appcompat 主题中的 windowActionBarOverlay 属性设置为 true,您正在绘制的 relativeLayout 仅从它知道的顶部开始,即操作栏下方。需要在主样式中设置,不能在actionbarstyle中设置
然后你可以将toolbarstyle中的android:background设置为透明以获得想要的效果
显示我们在项目中使用的一些代码以获得透明工具栏:
<style name="ToolBarStyle.Transparent" parent="">
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
<item name="android:background">@android:color/transparent</item>
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
注意,toolbar style是在xml中的一个toolbar上设置的,后面设置为actionbar。
关于android - ActionBar 覆盖不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31604711/