1

I have an Activity where I would like to have it's ActionBar transparent.

I am using API Level 18 and my Activity is an AppCompatActivity

I have tried many solutions on StackOverFlow but they dont seem to work

This is the latest one I tried

<!-- Application theme. -->
<style name="AppTheme.TransparentActionBar" 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">@android:color/transparent</item>
    <item name="android:windowActionBarOverlay">true</item>

    <!-- Support library compatibility -->
    <item name="background">@android:color/transparent</item>
    <item name="windowActionBarOverlay">true</item>
</style>

It simply turned the ActionBar to white. All solutions I've came up with turns the ActionBar to white.

Any thoughts?

I have also tried this code

protected void onCreate(Bundle savedInstanceState) {
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    super.onCreate(savedInstanceState);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    setContentView(R.layout.activity_login);

}

My activity_login.xml

<?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:background="@color/colorYellow"
    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=".LoginActivity">

</RelativeLayout>

EDIT

Actually the ActionBar is transparent. But the contentView itself is not underneath it. How can I possibly place the contentView underneath the ActionBar?

JayVDiyk
  • 4,277
  • 22
  • 70
  • 135

2 Answers2

1

Found the solution, it is a answer by this guy

This is for AppCompatActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    super.onCreate(savedInstanceState);
}
Community
  • 1
  • 1
JayVDiyk
  • 4,277
  • 22
  • 70
  • 135
0
public void setTransparentStatusBar() {
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            Window window = getWindow();
            if (window != null) {
                window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                        WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

                window.getAttributes().flags &= (~WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            }
            window.setStatusBarColor(Color.parseColor("#00000000"));

        }
    }

Call this in onCreate() of the activity! It worked for me, I hope this helps!

Yash Ladia
  • 393
  • 5
  • 15