Android Custom ProgressDialog Implementation

Source: Internet
Author: User

First look at the effect:

1.string.xml file, ProgressDialog is inherited and dialog, first set the ProgressDialog style, set the background transparent color.

 <style name= "Customdialog" parent= "@android: Style/theme.dialog" > <item name= "Android:windowframe" >@null  </item> <item name= "android:windowisfloating" >true  </item> <item name= "Android:windowcontentoverlay" >@null
    </item> <item name= "Android:windowanimationstyle" > @android:style/animation.dialog</item>            <item name= "Android:windowsoftinputmode" >stateUnspecified|adjustPan</item> </style> <style name= "Customprogressdialog" parent= "@style/customdialog" > <item name= "Android:windowbackground" &G t; @android:color/transparent</item> <item name= "Android:windownotitle" > true  </item> </style> 

2.customprogressdialog.xml file, define your own layout, because I need only a progress bar and a series of display content, so layout comparison orders

<?xml version= "1.0" encoding= "Utf-8"?> <LinearLayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "Horizontal" > <ImageView Android:id= "@+id/loadingimageview"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@anim/progress_round"/> <TextView Android:id= "@+id/id_tv_loadingmsg"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center_vertical"android:textsize= "20DP"/> </LinearLayout>

3.progress_round.xml file. This file loops through the images in order to achieve the effect of rotation.

<?xml version= "1.0" encoding= "Utf-8"?> <animation-list     xmlns:android= "http// Schemas.android.com/apk/res/android "     android:oneshot=" false ">     <item android:drawable=" @ Drawable/progress_1 "android:duration=" "/>     <item android:drawable=" @drawable/progress_2 "Android: duration= "/>     <item android:drawable=" @drawable/progress_3 "android:duration="/> "     < Item android:drawable= "@drawable/progress_4" android:duration= "/>     <item android:drawable=" @drawable /progress_5 "android:duration=" "/>     <item android:drawable=" @drawable/progress_6 "android:duration=" "/>     <item android:drawable=" @drawable/progress_7 "android:duration=",/> <item     android :d rawable= "@drawable/progress_8" android:duration= "/> </animation-list>

4.customprogressdialog.java file

 Packagecom.lxd.widgets; ImportCOM.LXD.ACTIVITY.R;ImportAndroid.app.Dialog;ImportAndroid.content.Context;Importandroid.graphics.drawable.AnimationDrawable;Importandroid.view.Gravity;ImportAndroid.widget.ImageView;ImportAndroid.widget.TextView; /******************************************************************** * [Summary] * TODO Please briefly describe the functions implemented by this class here. Because this annotation is primarily intended to generate tip help in an IDE environment, be brief and concise * [Remarks] * TODO Please describe in detail the functionality of the class, how to invoke it, considerations, and relationships with other classes. *******************************************************************/  Public classCustomprogressdialogextendsDialog {PrivateContext context =NULL; Private StaticCustomprogressdialog Customprogressdialog =NULL;  PublicCustomprogressdialog (Context context) {Super(context);  This. Context =context; }          PublicCustomprogressdialog (Context context,inttheme) {        Super(context, theme); }          Public StaticCustomprogressdialog createdialog (context context) {Customprogressdialog=NewCustomprogressdialog (Context,r.style.customprogressdialog);        Customprogressdialog.setcontentview (R.layout.customprogressdialog); Customprogressdialog.getwindow (). GetAttributes (). Gravity=Gravity.center; returnCustomprogressdialog; }       Public voidOnwindowfocuschanged (BooleanHasfocus) {                 if(Customprogressdialog = =NULL){            return; } ImageView ImageView=(ImageView) Customprogressdialog.findviewbyid (R.id.loadingimageview); Animationdrawable animationdrawable=(animationdrawable) imageview.getbackground ();    Animationdrawable.start (); }      /*** * [Summary] * settitile title *@paramstrtitle *@return     *     */     Publiccustomprogressdialog settitile (String strtitle) {returnCustomprogressdialog; }         /*** * [Summary] * setmessage prompt content *@paramstrmessage *@return     *     */     Publiccustomprogressdialog setmessage (String strmessage) {TextView tvmsg=(TextView) Customprogressdialog.findviewbyid (r.id.id_tv_loadingmsg); if(Tvmsg! =NULL) {tvmsg.settext (strmessage); }                 returnCustomprogressdialog; }}

5. Call

Customprogressdialog ProgressDialog = Customprogressdialog.createdialog (this);

Android Custom ProgressDialog Implementation

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.