Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Android Action Bar transparent

I'm trying to make my AppCompatActivity's Action Bar transparent. I'm looking for something like this (from this app).

I've tried doing this:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

But the only thing it does is making views go behind the action bar.

What can I do so that the text and the navigation drawer button are the only visible things on it?

Edit: Here is my xml layout

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipeRefresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <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:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            tools:context="my.package.name"
            android:id="@+id/relLayout">

            <!-- My views are here -->

        </RelativeLayout>

    </ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>
like image 627
marti201 Avatar asked Oct 15 '25 14:10

marti201


1 Answers

For future readers:

I did it by setting the color of the action bar to a fully transparent color, Color.TRANSPARENT. Here is my code:

 getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

 getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
like image 84
marti201 Avatar answered Oct 18 '25 19:10

marti201



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!