Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBarCompat & Transparency

I would like to make the ActionBar in the support library fully transparent, however, it seems that changing the background drawable won't suffice since the backgrounds stack. If you put a semi-transparent background you end up with the default background behind it.

Does anyone know a way to remove that background?

This is what happens:

Actionbar

The code for the background drawable:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#66336688"/>
</shape>

As you can see, the drawable has a transparent blue that overlaps with the default gray background.

like image 878
CristianGuerrero Avatar asked Aug 22 '13 03:08

CristianGuerrero


2 Answers

Ok, I found the solution messing around with the SDK. It seems that it is pretty simple, you need to do 3 things:

  • Create a background drawable as shown on my question.
  • Create an ActionBar style like so:

    <!-- Application theme. -->
    <style name="AppTheme" 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">@drawable/actionbar_background</item>
        <item name="android:windowActionBarOverlay">true</item>
    
        <!-- Support library compatibility -->
        <item name="background">@drawable/actionbar_background</item>
        <item name="windowActionBarOverlay">true</item>
    </style>
    
  • Use the Window feature for ActionBar overlay using the Support method (ignore Eclipse's warning regarding API level for the constant; I used the SuppressLint annotation to remove the warning):

    @SuppressLint("InlinedApi") @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    setContentView(R.layout.activity_home);}
    
like image 194
CristianGuerrero Avatar answered Nov 05 '22 05:11

CristianGuerrero


ChristianGuerrero answer is great but you should directly put the item:

<item name="android:windowActionBarOverlay">true</item>

inside the AppTheme style. Then you don't have to add anything in your onCreate method.

like image 30
gleroyDroid Avatar answered Nov 05 '22 05:11

gleroyDroid