What's the meaning of android:progressBarStyle attribute in ProgressBar?

☆樱花仙子☆ 提交于 2019-12-29 11:48:20

问题


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.


回答1:


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:

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

style="?android:attr/progressBarStyleSmall"

style="?android:attr/progressBarStyle"

style="?android:attr/progressBarStyleLarge"

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.




回答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" />



回答3:


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.



来源:https://stackoverflow.com/questions/4288807/whats-the-meaning-of-androidprogressbarstyle-attribute-in-progressbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!