Android ProgressBar horizontal progress bar color settings, Android progressbar

Source: Internet
Author: User

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.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.