Android ProgressBar horizontal progress bar color settings, Android progressbar
Android provides the horizontal progress bar style. In actual development, it is almost impossible to use the default style because it is too ugly. ^_^
Therefore, we need to customize the color when using a custom Style File.
Add the progressbar. xml file in the drawable directory to set the Default background color and progress bar color.
(Gradient color is supported)
Code:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@android:id/background"> <shape> <corners android:radius="5dip" /> <gradient android:angle="0" android:centerColor="#ff5a5d5a" android:centerY="0.75" android:endColor="#ff747674" android:startColor="#ff9d9e9d" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <corners android:radius="5dip" /> <gradient android:angle="0" android:centerColor="#80ffb600" android:centerY="0.75" android:endColor="#a0ffcb00" android:startColor="#80ffd300" /> </shape> </clip> </item> <item android:id="@android:id/progress"> <clip> <shape> <corners android:radius="5dip" /> <gradient android:angle="0" android:endColor="#8000ff00" android:startColor="#80ff0000" /> </shape> </clip> </item></layer-list>
The layout file is defined as follows:
<ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:layout_height="7.5dp" android:max="100" android:progress="80" android:layout_marginRight="8dp" android:progressDrawable="@drawable/progressbar" android:visibility="visible"/>
In android, there is a ProgressBar progress bar component and a button in mainxml. How can this progress bar be hidden in the initial state?
In mian. xml, set the visibility of ProgressBar to invisible. In the java file, find the ProgressBar ID through findViewById (), assume it is "progressBar", and finally write progressBar In the listener function of the button. setVisibility (View. VISIBLE); that's it.
Android ProgressBar question: how to set the width of ProgressBar?
The layout_width attribute of ProgressBar sets the width of the entire component, rather than the width of the progress bar. This image is a composite layered cut chart. The specific size is determined by the image specified by the progressDrawable attribute you set.
If you do not understand what a layered cut chart is, you can view the android document, especially through this layered cut chart, you can freely adjust the progress bar, not just the size value.