Android custom progressdialog

Source: Internet
Author: User

(1) define the defineprogressdialog class, inherit the progressdialog, and rewrite the oncreate () method.

Package COM. lizhen. animation; import COM. lizhen. key. study. r; import android. app. progressdialog; import android. content. context; import android. OS. bundle; import android. widget. textview; public class defineprogressdialog extends progressdialog {private string message; private textview define_progress_msg; Public defineprogressdialog (context) {super (context); message = "loading... "; // todo auto-generated constructor stub} public defineprogressdialog (context, string message) {super (context); this. message = message;} @ overrideprotected void oncreate (bundle savedinstancestate) {// todo auto-generated method stubsuper. oncreate (savedinstancestate); setcontentview (R. layout. define_progress_dialog); define_progress_msg = (textview) findviewbyid (R. id. define_progress_msg); define_progress_msg.settext (Message );}}

 

(2) define_progress_msg.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:background="@drawable/progress_bg"    android:orientation="vertical"    android:paddingBottom="10sp"    android:paddingTop="10sp"    android:paddingLeft="10sp"    android:paddingRight="10sp" >    <ProgressBar         android:id="@+id/ios_progressbar"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center_horizontal"        style="@style/DefineprogressBarStyleSmall"/><TextView     android:id="@+id/define_progress_msg"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center_horizontal"    android:textSize="12sp"/></LinearLayout>

 

(3) set the progress bar style, customize defineprogressbarstylesmall, and add define_progressbar to the style:

<?xml version="1.0" encoding="utf-8"?><resources>    <style name="DefineprogressBarStyleSmall" parent="android:style/Widget.ProgressBar"><item name="android:indeterminateDrawable">@drawable/progress</item><item name="android:minWidth">48dp</item>          <item name="android:maxWidth">48dp</item>          <item name="android:minHeight">48dp</item>          <item name="android:maxHeight">48dp</item> </style></resources>

(4) define another progress bar background image, set the animation of the image, rotate around the center, and add progress. xml under drawable:

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" >    <item>        <rotate            android:pivotX="50%"            android:pivotY="50%"            android:fromDegrees="0"            android:toDegrees="360"            android:drawable="@drawable/progress_round"            >        </rotate>    </item></layer-list>

 

 

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.