Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android progress bar style syntax

Tags:

android

In a progress bar definition the style is defined as

style="?android:attr/progressBarStyleHorizontal"

I'm not clear on how this syntax works. Can someone explain this syntax?

like image 665
prashant Avatar asked Jan 04 '12 15:01

prashant


People also ask

What is progress bar with example?

Progress bars are used to show progress of a task. For example, when you are uploading or downloading something from the internet, it is better to show the progress of download/upload to the user. In android there is a class called ProgressDialog that allows you to create progress bar.

How do I make my progress bar horizontal Android?

In Android, by default a progress bar will be displayed as a spinning wheel but If we want it to be displayed as a horizontal bar then we need to use style attribute as horizontal. It mainly use the “android. widget. ProgressBar” class.

What are the different types of progress bars?

There are two types of progress bars: determinate and indeterminate .


2 Answers

That syntax is used to reference a system style attribute, and it's similar to the syntax used to reference a resource predefined by the Android system: whereas in the general resource case you use e.g. @android:drawable/ic_media_play to reference a Drawable represented by the file ic_media_play.png in the value of an android:src attribute for the ImageButton UI element included in an XML layout, the attribute reference is built using a ? instead of a @, but for the rest is composed following the same rules and works in the same way.

In particular, attributes are usually stored in res/values/attrs.xml, where you can find (looking at the system resources stored in the Android SDK) the following

<attr name="progressBarStyleHorizontal" format="reference" />

indicating that the attribute is a reference to some other resource. The style attribute is defined in res/values/themes.xml in the following fashion:

<item name="progressBarStyleHorizontal">
    @android:style/Widget.ProgressBar.Horizontal
</item>

which is indeed a reference to the style Widget.ProgressBar.Horizontal in the system res/values/styles.xml as already described by another answer.

Note that, in contexts when the system knows to expect a reference to an attribute resource, you may even omit the resource type (i.e. the attr/ part), leading to a syntax such as:

android:textColor="?android:textColorSecondary"

You may find slightly more information on the Android developer guide

like image 156
Giulio Piancastelli Avatar answered Sep 30 '22 12:09

Giulio Piancastelli


android:attr means this style is picked from frameworks of android. So if you browse the source of styles.xml from frameworks http://bit.ly/yBC5pM and search progressBarStyleHorizontal, You can see it inherits from Widget.ProgressBar.Horizontal

<style name="Widget.ProgressBar.Horizontal" parent="@style/Widget.ProgressBar">
    <item name="maxHeight">20.0dip</item>
    <item name="indeterminateOnly">false</item>
    <item name="indeterminateDrawable">@drawable/progress_indeterminate_horizontal</item>
    <item name="progressDrawable">@drawable/progress_horizontal</item>
    <item name="minHeight">20.0dip</item>
</style>

All the above properties + properties from Widget.Progressbar(Since its parent is this) will get inherited to your Progressbar.

like image 25
nandeesh Avatar answered Sep 30 '22 14:09

nandeesh