0

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.

quangson91
  • 1,044
  • 1
  • 16
  • 30
  • use this line in your actionbarstyle..... #00000000 – Pragnesh Ghoda シ Jul 29 '14 at 09:44
  • I added. But it not working. :( – quangson91 Jul 29 '14 at 09:48
  • @Prag's It still have a black line in bottom actionbar. (I run on android v4.3) – quangson91 Jul 29 '14 at 09:50
  • @speedDeveloper I want to set actionbar height.(not get actionbar height) – quangson91 Jul 29 '14 at 09:51
  • See this to set the ActionBar height: [Set ActionBar height][1] [1]: http://stackoverflow.com/questions/17439683/how-to-change-action-bar-size – pczern Jul 29 '14 at 09:54
  • It's not actionbar support v7. :( I've try use actionbar sherlock. It's work for me. But actionbar support v7 - Make me headache. – quangson91 Jul 29 '14 at 10:41

2 Answers2

2

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>

Stefan
  • 5,203
  • 8
  • 27
  • 51
Stephane Mathis
  • 6,542
  • 6
  • 43
  • 69
  • Thank you. You mean I can't change height of actionbar. My application only working on portrait. So how I can't change height of actionbar support v7. (Does it can't change ?) – quangson91 Jul 29 '14 at 10:22
  • Thanks you. I think I will change to use Actionbar Sherlock. – quangson91 Jul 29 '14 at 10:42
  • It will also work with ABS, the only difference is to use `getSupportActionBar()`. – Stephane Mathis Jul 30 '14 at 07:53
  • Not a terribly large difference per se but instead of `Color.parseColor("#00000000")` I'd vote for `Color.TRANSPARENT`. Simpler and self-documenting. – Gábor Dec 07 '14 at 23:36
1

try this :

ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#000000")));
Mero
  • 622
  • 12
  • 24