41

I've been looking through the documentation for ProgressBar class and found these attributes:

  • android:progressBarStyle
  • android:progressBarStyleHorizontal
  • android:progressBarStyleLarge
  • android:progressBarStyleSmall

These four parameters are supposed to be a reference to some style as I take it. So the question is, what are these for? Style for the progress bar is set via android:style attribute and a reference to the global style attributes.

Documentation doesn't say anything helpful, searched the Web, found nothing.

Jonik
  • 80,077
  • 70
  • 264
  • 372
Malcolm
  • 41,014
  • 11
  • 68
  • 91

3 Answers3

75

The four attributes that you mention can be applied to a ProgressBar's style like so:

style="?android:attr/progressBarStyleHorizontal"

The style constant android:progressBarStyleHorizontal is your typical incremental progress bar:

alt text

While the other three are varying sizes of the same circular progress bar:

style="?android:attr/progressBarStyleSmall"

alt text

style="?android:attr/progressBarStyle"

alt text

style="?android:attr/progressBarStyleLarge"

alt text

Update:

According to adamp's comments:

These are attributes of the theme that point at themed styles you can use for progress indicators...They are not attributes for ProgressBar itself.

McStretch
  • 20,495
  • 2
  • 35
  • 40
  • 1
    The documentation means what it says, it's just not terribly verbose about it. ;) These are attributes of the theme that point at themed styles you can use for progress indicators. Their exact values can change from theme to theme, it's just a layer of indirection. This answer is correct. Set the style attribute to one of these. They are not attributes for ProgressBar itself. – adamp Nov 27 '10 at 17:34
  • @adamp: Thanks for the clarification, I'll update my answer to reflect your comments. – McStretch Nov 27 '10 at 21:21
  • So the answer is basically "They are not attributes for ProgressBar itself". Yes, I know how to set the style of the progress bar. :) I was only wondering, what changes if you change the attributes, but if these attributes aren't actually attributes, everything becomes clear. P.S. Some parts of Android documentation really suck. – Malcolm Nov 27 '10 at 23:22
  • 1
    They *are* attributes, but they're attributes for themes, not for the ProgressBar widget. The "?android:attr/foo" syntax with the "?" sigil means, "resolve the resource contained in this theme attribute within the current theme." – adamp Nov 27 '10 at 23:44
  • 1
    I designed and custom view and using it as an lib component. Here I'm using progress bar but not able to change style="?android:attribute for same. It showing same progress bar I checked same with some other parameter to make sure I'm using same. Any suggestion !!! – CoDe Jul 07 '14 at 10:29
2

In case if someone is looking for full block of code

<ProgressBar
android:id="@+id/ProgressBar2"
style="?android:attr/progressBarStyleLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Zohab Ali
  • 8,426
  • 4
  • 55
  • 63
1

The confusing part is that normally, you can define a default style for a widget (e.g. a button) like this:

<item name="android:buttonStyle">@style/Widget.AppCompat.Button.Colored</item>

All buttons will then by default have this style applied.

One would think that the progressBarStyle attribute would do the same for ProgressBar if doing this:

<item name="android:progressBarStyle">@style/Widget.AppCompat.ProgressBar</item>

But that is not the case, since progressBarStyle belongs to the ActionBar styleable.

Timon Langlotz
  • 418
  • 4
  • 7
  • When you're using AppCompat you're supposed to use `progressBarStyle` instead of `android:progressBarStyle`. That's true for all widgets except `android:textViewStyle`. Agreed that it's confusing. – Eugen Pechanec Nov 12 '19 at 21:18
  • Not true, you only need to do so for attributes that belong to a `AppCompat...` widget (e.g. `AppCompatEditText`, `AppCompatImageView`, etc.). There's no `AppCompatProgressBar`, so defining `progressBarStyle` without the Android prefix has no effect. – Timon Langlotz Nov 13 '19 at 08:30
  • Damn, you're right, forgot about that. And it's not even wired to AppCompat's `progressBarStyle`. According to `ProgressBar` source code it should pick up `android:progressBarStyle` by default. Why don't you investigate why that doesn't work in your case? Stack Overflow is not a forum and your post doesn't really answer the question. – Eugen Pechanec Nov 13 '19 at 08:39