Custom Translucent Android ActionBar Custom Translucent Android ActionBar android android

Custom Translucent Android ActionBar


If you want your activity to be fullscreen but still show an actionbar, but with an alpha you have to request overlaymode for the actionbar in onCreate() of your activity:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);//getWindow().requestFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY); << Use this for API 7+ (v7 support library) 

Then after you call setContentView(..) (since setContentView(..) also initializes the actionbar next to setting the content) you can set a background drawable on your actionbar:

getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg));

which can be a shape drawable with an alpha put in res/drawable:

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">     <solid android:color="#BB000000" /> </shape>

You could also do this completely programatically by creating a ColorDrawable:

getActionBar().setBackgroundDrawable(new ColorDrawable(Color.argb(128, 0, 0, 0)));

Otherwise ofcourse you can hide the actionbar completely; in that case you can set a custom theme on your activity in your manifest:

@android:style/Theme.NoTitleBar.Fullscreen

or programmatically by calling

getActionBar().hide();


In addition to the correct answer, if you are using AppcomatActivity, call supportRequestWindowFeature instead of

Old Version:getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

You want to use:

@Overrideprotected void onCreate(Bundle savedInstanceState) {    supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);    super.onCreate(savedInstanceState);}


I think you should be able to do this using the Window flag FEATURE_ACTION_BAR_OVERLAY.

Before you call setContentView() in your activity,

Call:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

And it will use an overlaid ActionBar instead of pushing down your window.