15

Is there a way to make the ActionBar transparent in Material Design via Appcompat-v7 21? This is not working unfortunately.

  <item name="colorPrimary">@android:color/transparent</item>

Also not the old:

  <style name="Widget.Styled.ActionBar" parent="Widget.AppCompat.Light.ActionBar">
        <item name="android:background">@android:color/transparent</item>
  </style>
ligi
  • 39,001
  • 44
  • 144
  • 244

4 Answers4

26
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ACTION BAR STYLES -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:background">@drawable/actionbar_background</item>
    <item name="android:windowActionBarOverlay">true</item>

    <!-- Support library compatibility -->
    <item name="background">@drawable/actionbar_background</item>
    <item name="windowActionBarOverlay">true</item>
</style>
chris
  • 4,332
  • 5
  • 41
  • 61
Danial Hussain
  • 2,488
  • 18
  • 38
24

Actually, it's quite easy and simple.

  1. Just ensure that you use RelativeLayout to lay Toolbar and the body.
  2. Put the Toolbar in the last.
  3. Put transparent color for android:background attribute of the Toolbar

This is an example of a working code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:orientation="vertical">

    <fragment
        android:id="@+id/fragment_editor"
        android:name="ichsan.myapp.HelloFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout="@layout/fragment_editor" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="#10000000"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

</RelativeLayout>

Hope it answers the question.

sancho21
  • 3,511
  • 1
  • 39
  • 45
  • Nice. Was working on this for a while before finding your post. – Lars May 04 '15 at 20:27
  • 1
    Has anyone come up with a clean solution on how to swap between an overlaid Toolbar and a top-anchored Toolbar depending on which Fragment is showing within the Activity? – Ryan Jul 28 '15 at 20:46
  • although this does work, but the `android.support.design.widget.AppBarLayout` must be removed. And since it removed the original collapsed toolbar will remain on screen. – Robert Oct 27 '15 at 03:55
  • could you please tell how to implement the above layout in an Activity (not FragmentActivity) with "fragment_editor" in **tools:layout="@layout/fragment_editor"** as a recyleview? – OnePunchMan Jan 20 '16 at 11:12
1

Step:

1. put below style into v21\styles.xml

<style name="TransperantToolbar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="windowActionBarOverlay">true</item>
</style>

2. Your toolbar xml code

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/TransperantToolbar"/>

Output

Dhaval Jivani
  • 9,467
  • 2
  • 48
  • 42
0

None of the above did the trick for me (or at least not by themselves) using appcompat v7 23 and a CoordinatorLayout, which is most likely the culprit. If you are going that route, then you probably have a main activity layout that looks like

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.farmdog.farmdog.MainActivity">

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
                 app:layout_anchor="@+id/appbar"
                 app:layout_anchorGravity="top"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <!--android:theme="@style/AppTheme.AppBarOverlay">-->
     ...

Notice the two layout anchor lines above - those did it for me.

kellogs
  • 2,837
  • 3
  • 38
  • 51