Android: How do I change the height of a ProgressBar?

33,853

Solution 1

If your progress bar is defined in the XML layout, it looks like you define its height like so:

<ProgressBar  
android:minHeight="20dip" 
android:maxHeight="20dip"/>

However I'm just making a guess from this article.

Solution 2

You need to replace

style=”?android:attr/progressBarStyleHorizontal”

to

style="@android:style/Widget.ProgressBar.Horizontal"

and layout_height will work

android:layout_height="50dp"

Solution 3

The trick is to have your ProgressBar use the "old", none halo, style. Otherwise it will use a 9-patch image as a progress drawable and you can't change the height unless you manipulate the image. So here is what I did :

the progressbar :

<ProgressBar
  android:id="@+id/my_progressbar"
  style="@android:style/Widget.ProgressBar.Horizontal"
  android:layout_width="fill_parent"
  android:layout_height="10dp"
  android:progressDrawable="@drawable/horizontal_progress_drawable_red" />

the progress drawable (horizontal_progress_drawable_red.xml) :

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@android:id/background">
        <shape>
            <solid android:color="#808080"/>
        </shape>
    </item>

    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <solid android:color="#80ff0000"/>
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <solid android:color="#ff0000"/>
            </shape>
        </clip>
    </item>

</layer-list>

Solution 4

Can use this code :

mProgressBar.setScaleY(3f);

Or use custom style

values->styles.xml

<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>

Then in your ProgressBar add:

style="@style/tallerBarStyle"
Share:
33,853
Tomek
Author by

Tomek

Updated on August 16, 2022

Comments

  • Tomek
    Tomek over 1 year

    I was wondering what is the easiest way to change the height of a ProgressBar in Android?

    Thanks,

    Tomek

  • Taranfx
    Taranfx about 12 years
    How about API >11 where its automatically added to actionbar?
  • clocksmith
    clocksmith almost 10 years
    what is the root element for the progress drawable supposed to be? EDIT: <layer-list>
  • Bhavik Mehta
    Bhavik Mehta about 9 years
    Worked like a charm ! Thanks
  • Alok Rajasukumaran
    Alok Rajasukumaran almost 8 years
    How to add attributes like color?!
  • Luke
    Luke almost 7 years
    You can set the color of the progress and the progress background with "android:progressTint" and "android:progressBackgroundTint" in your SeekBar XML.
  • Mark O'Sullivan
    Mark O'Sullivan almost 7 years
    @Luke how do you do that for devices which are pre API 21?