quangson91
quangson91

Reputation: 1094

Actionbar support v7 background not transparent

I have problem: 1st: I want to custom height of actionbar but it not working.

This is content in my theme.

<style name="Theme.MyAppTheme" parent="@style/Theme.AppCompat.Light">
        <item name="actionBarStyle">@style/Theme.MyAppTheme.ActionBarStyle</item>
        <item name="windowActionBarOverlay">false</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="actionBarSize">46dp</item>
        <item name="android:height">46dp</item>
        <item name="height">46dp</item>
  </style>

2nd. If can't change height of actionbar please tell me: "How to make background of actionbar transparent.". (I will create custom view of actionbar with Root Layout height 48dp. Then create sub view with heigh = 46dp :) ).

Please help me. Thanks so much.

Upvotes: 0

Views: 1016

Answers (2)

Stephane Mathis
Stephane Mathis

Reputation: 6622

Your problem is that you set windowActionBarOverlay to false.

To have your content below the action bar :

Add this in your style.xml from the values folder :

    <item name="windowActionBarOverlay">true</item>
    <item name="windowContentOverlay">@null</item>
    <item name="android:windowContentOverlay">@null</item>

And this in your style.xml from the values-v14 folder :

    <item name="windowActionBarOverlay">true</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="windowContentOverlay">@null</item>

Then in your layouts, you can get the size of the action bar with this :

    android:layout_marginTop="?attr/actionBarSize" 

You need to use the attribute instead of "48dp" or "46dp" because the height changes according to different configuration (portrait/landscape, tablet/phone, ...).

To make the action bar transparent, you need to change the background. Either in your theme or by code.

    getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));

EDIt : I've just checked in one of my project. Apparently, setting a margin on the root of a layout for an activity doesn't work. So I did something like that :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<View //invisible view, to prevent warning
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:visibility="gone" >
</View>

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="?attr/actionBarSize" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

         //real content

    </LinearLayout>
</ScrollView>

Upvotes: 2

Mero
Mero

Reputation: 632

try this :

ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#000000")));

Upvotes: 1

Related Questions