Search code examples
androidprogress-barandroid-4.0-ice-cream-sandwich

How to increase height of ProgressBar in ICS/JB


I am using the Android progressbar in one of my widgets:

<ProgressBar
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="?android:attr/progressBarStyleHorizontal"
        android:id="@+id/progressbar_Horizontal"
        android:max="100"/>

In Android 2.x it looks well, like in the following picture. I have written the % on top of the bar itself.

ProgressBar in Android 2.x

But if I change in the Android Manifest

android:targetSdkVersion

to "15" the progressbar looks totaly different. It is now a thin blue line instead of a bar. The problem is that I have written above the progress bar some text, in particuallary % of the progress. Thus as the bar is so thin this looks odd.

I cannot figure out how to increase the height of the bar again to e.g. 50dp. If I try android:layout_height="50dp" it stays still same thin.


Solution

  • First, you need to define the style of your progress bar in values->styles.xml of your project. something like:

    <style name="tallerBarStyle" parent="@android:style/Widget.SeekBar">
        <item name="android:indeterminateOnly">false</item>
        <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
        <item name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item>
        <item name="android:minHeight">8dip</item>
        <item name="android:maxHeight">20dip</item>
    </style>
    

    Edit the maxHeight to your desired height.

    Then in your ProgressBar add:

    style="@style/tallerBarStyle"