The Google Maps application has a transparent ActionBar, through which the map is visible.
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?
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With