Customize ProgressBar Android

1

I would like to develop a% custom% to use in my application, but I am not sure how to do this.

Is it necessary to create a subclass of ProgressBar ? Can you only do in ProgressBar ?

I would like you to give me a basic example of how to customize this component.

Follow my code, with no customization at all.

Main_activity.xml file

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <ProgressBar 
        android:id="@+id/progressBar"
        android:layout_width="250dip"
        android:layout_height="wrap_content"
        android:max="100"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        style="?android:attr/progressBarStyleHorizontal"/>

</RelativeLayout>

MainActivity class

import android.app.Activity;
import android.os.Bundle;
import android.widget.ProgressBar;

public class MainActivity extends Activity{

    private ProgressBar progressBar;
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        progressBar = (ProgressBar)findViewById(R.id.progressBar);
    }

    //Mais código

}
    
asked by anonymous 23.11.2014 / 00:25

1 answer

3

I do not know how to explain how to do more, but I'll show you the example I use:

<ProgressBar
        style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:id="@+id/progressBar"
        android:layout_below="@+id/edittext_url"
        android:layout_centerHorizontal="true"
        android:progressDrawable="@drawable/custom_progressbar" />

Warning for the android:progressDrawable="@drawable/custom_progressbar" line

custom_progressbar.xml (res \ drawable)

<?xml version="1.0" encoding="utf-8"?>
<layer-list
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <gradient 
                    android:startColor="#ff49a8a6"
                    android:centerColor="#ff49a8a6"
                    android:endColor="#ff49a8a6"
                    android:angle="270.0" android:centerY="1.0"  />
            </shape>
        </clip>
    </item>
</layer-list>

Result:

    
05.02.2015 / 21:05