Transparent Actionbar: Custom Tabcolor

Transparent Actionbar: custom tabcolor

Call setStackedBackgroundDrawable() on your ActionBar:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));

This produces (as an example with some random icons and tabs, and two different bluish background colors to highlight the effect):

Sample Image

(The refresh icon is the default one, which comes with a slight transparency. The other icons are custom test icons with color #FFFFFFFF, that is, no transparency).

Make Android Action Bar transparent

For future readers:

I did it by setting the color of the action bar to a fully transparent color, Color.TRANSPARENT.
Here is my code:

 getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

how to make the actionbar transparent

Question 1: It's down to device space constraints. The first paragraph in the Android documentation for tabs in the action bar show that if there isn't room it will split the tabs to a separate bar.

http://developer.android.com/guide/topics/ui/actionbar.html#Tabs

Question 2: You need to set the drawable for the background and the stacked background of the action bar to your transparent drawable. (Edit: Links in Ye Lin Aung's comment show how to do that).

Question 3: It sounds like you are looking for a navigation drawer layout arrangement to me. The best place to start on this would be this link:

http://developer.android.com/training/implementing-navigation/nav-drawer.html

Edit: The pattern will work the same for both mobile and tablets (though you may want to have an xml for smaller screens that have a slightly thinner drawer sizes).

The android documentation in the link above states that the drawer width should be set in dp units and that the drawer height matches the parent view. The drawer width should be no more than 320dp so the user can always see a portion of the main content. This should allow most phones to view it in both portrait and landscape and still see some content.

Actionbar support v7 background not transparent

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>

Transparent ActionBar is not working

try this code

<item name="android:background">@null</item>

If this does'nt helps you, Check this link with this Code

Call setStackedBackgroundDrawable() on your ActionBar

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));

OR this link , this code

<style name="MyTheme" parent="Theme.Sherlock">
...
<item name="windowActionBarOverlay">true</item> <!-- for ActionBarSherlock -->
<item name="android:windowActionBarOverlay">true</item>
</style>

For making ActionBar Transparent.Hope this helps.

Navigation Drawer Below Transparent Actionbar

To achieve that you have to calculate Action Bar height and set marginTop to your navigation drawer. Use this method to calculate Action bar height:

 public static int CalculateActionBar(Context context){
// Calculate ActionBar height
TypedValue tv = new TypedValue();
if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {

int mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
return mActionBarHeight;
}
return 0;
}

Then from java set Margin Top to your Navigation Drawer Object.

Doing this you will achieve a Navigation Drawer below Action Bar



Related Topics



Leave a reply



Submit