Isquierdo
Isquierdo

Reputation: 745

ActionBar Overlaying Not Working

I use the Developer Guide to enable ActionBar Overlaying, but is not working

The action bar is not transparent and the layout is below the ActionBar

Result: Result

Expected:

Expected

Style

    <!-- 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>

main_layout

<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>

Upvotes: 1

Views: 1267

Answers (1)

ThMBc
ThMBc

Reputation: 804

You need to set the windowActionBarOverlay attribute in the Appcompat theme to true, the relativeLayout you're drawing only starts from the top it knows, which is below the action bar. It needs to be set in the main style, not in the actionbarstyle

Then you can set the android:background in the toolbarstyle to transparent for the desired effect

To show some code we use in our projects to get a transparent toolbar:

<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>

mind, the toolbar style is set on a toolbar in xml, which is later set as the actionbar.

Upvotes: 2

Related Questions