3

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.

TZHX
  • 4,946
  • 15
  • 45
  • 55
tobias
  • 2,282
  • 3
  • 33
  • 52

2 Answers2

9

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"

Hope that helps. :)

kdroider
  • 721
  • 5
  • 20
  • Perfect thx. Can you also tell me how to change the color of that bar? – tobias Sep 27 '12 at 13:31
  • To change the color of the progressBar you need to create another xml that will contain your desired color change. Then, set that xml as the value of android:progressDrawable in your progressBar. See the answer given here: http://stackoverflow.com/a/5745923/1594522 – kdroider Sep 28 '12 at 01:20
1

You need to replace

style=”?android:attr/progressBarStyleHorizontal”

to

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

and layout_height will work

android:layout_height="50dp"
rnofenko
  • 8,513
  • 2
  • 44
  • 52