Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show ImageView partly behind transparent ActionBar

The Google Maps application has a transparent ActionBar, through which the map is visible.

enter image description here

I am able to set the transparency of the ActionBar using this:

<style name="Theme.MyTheme" parent="android:style/Theme.Holo.Light">     <item name="android:actionBarStyle">@style/ActionBar</item> </style>  <style name="ActionBar" parent="@android:style/Widget.Holo.ActionBar">     <item name="android:background">#64000000</item> </style> 

But how can I show my ImageView behind the ActionBar?

like image 613
nhaarman Avatar asked Nov 14 '12 15:11

nhaarman


2 Answers

You can enable overlay mode of the ActionBar. To do it you have to set (android:)windowActionBarOverlay item in the theme to true.

<style name="MyTheme" parent="Theme.Sherlock">     ...     <item name="windowActionBarOverlay">true</item> <!-- for ActionBarSherlock -->     <item name="android:windowActionBarOverlay">true</item> </style> 
like image 123
Tomik Avatar answered Oct 04 '22 10:10

Tomik


You can also set it at run-time:

requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); 

This will the ActionBar a semi-transparent floating bar.

Like any requestWindowFeature..., this should be called before adding content.

After the setContentView, you can then set a background from your Drawable with this:

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

Change getActionBar with getSupportActionBar for ActionBarSherlock

actionbar_bg.xml with the root element of shape:

<solid android:color="#64000000" /> 

Although I find Tomik's solution great, this will be useful for those one-off cases for a few activities rather than an across the board style.

like image 42
Siddharth Lele Avatar answered Oct 04 '22 08:10

Siddharth Lele