Custom Transparent Background ProgressDialog

Source: Internet
Author: User

Implements a custom transparent background progressdialog by inheriting dialog+ frame animations.

Download resource address: http://download.csdn.net/download/shenyuanqing/8984687

Effect Animation:



Commprogressdialog:

Package Com.example.administrator.progressdialog;import Android.app.dialog;import Android.content.context;import Android.graphics.drawable.animationdrawable;import Android.view.gravity;import Android.view.KeyEvent;import Android.widget.imageview;import android.widget.textview;/** * Created by Administrator on 2015/7/29.    */public class Commprogressdialog extends Dialog {Private context context = NULL;    private int anim=0;    private static Commprogressdialog Commprogressdialog = null;        Public Commprogressdialog (Context context) {super (context);    This.context = context;        } public Commprogressdialog (context context, int theme, int anim) {Super (context, theme);    This.anim=anim; } public static Commprogressdialog createdialog (Context context,int anim) {commprogressdialog = new commprogress        Dialog (context, R.style.commprogressdialog, anim);        Commprogressdialog.setcontentview (R.layout.comm_progress_dialog); Commprogressdialog.geTwindow (). GetAttributes (). Gravity = Gravity.center;    return commprogressdialog;        public void Onwindowfocuschanged (Boolean hasfocus) {if (Commprogressdialog = = null) {return;        } ImageView ImageView = (ImageView) Commprogressdialog.findviewbyid (r.id.iv_loading);        if (anim!=0) {imageview.setbackgroundresource (anim);        } animationdrawable animationdrawable = (animationdrawable) imageview.getbackground ();    Animationdrawable.start ();        }/** * Set title * @param strtitle * @return * */Public Commprogressdialog settitile (String strtitle) {    return commprogressdialog; }/** * Set prompt content * @param strmessage * @return * * * public commprogressdialog setmessage (String Strmessa        GE) {TextView tvmsg = (TextView) Commprogressdialog.findviewbyid (r.id.tv_loading_msg);        if (tvmsg! = null) {Tvmsg.settext (strmessage);    } return Commprogressdialog;  }  /** Mask Return key **/@Override public boolean onKeyDown (int keycode,keyevent event) {if (Keycode==keyevent.keycode_ba        CK) return true;    Return Super.onkeydown (KeyCode, event); }}

Style.xml

<resources> <!--Base application theme.--<style name= "apptheme" par Ent= "Theme.AppCompat.Light.DarkActionBar" > <!--Customize your Theme here. -</style> <style name= "Customdialog" parent= "@android: Style/theme.dialog" > <item name= "a Ndroid: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= "Commprogressdialog" parent= "@style/customdialog" > &L T;item name= "Android:windowbackground" > @android:color/transparent</item> <item name= "Android: Windownotitle ">true</item> </style></resources> 

Comm_progress_dialog.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout    xmlns:android= "http://schemas.android.com/apk/ Res/android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "Horizontal" >    <imageview        android:id= "@+id/iv_loading" android:layout_width= "Wrap_        Content "        android:layout_height=" wrap_content "        android:background=" @anim/default_anim "        android: layout_gravity= "center"/>    <textview        android:id= "@+id/tv_loading_msg"        android:layout_width = "Wrap_content"        android:layout_height= "wrap_content"        android:layout_gravity= "center_vertical"        android:layout_marginleft= "5DP"        android:textsize= "16DP"/></linearlayout>


Default_anim.xml

<?xml version= "1.0" encoding= "Utf-8"? ><animation-list xmlns:android= "http://schemas.android.com/apk/res/ Android "android:oneshot=" false "> <item android:drawable=" "@mipmap/loading_1" android:duration= "></" item> <item android:drawable= "@mipmap/loading_2" android:duration= "></item> <item Android:dra wable= "@mipmap/loading_3" android:duration= "></item> <item android:drawable=" @mipmap/loading_4 " android:duration= "></item> <item android:drawable=" @mipmap/loading_5 "android:duration=" > " </item> <item android:drawable= "@mipmap/loading_6" android:duration= "All" ></item> <item Androi d:drawable= "@mipmap/loading_7" android:duration= "></item> <item android:drawable=" @mipmap/loading _8 "android:duration=" ></item> <item android:drawable= "@mipmap/loading_9" android:duration= "150" ></item> <item android:drawable= "@mipmap/loading_"Android:duration=" ></item> <item android:drawable= "@mipmap/loading_11" android:duration= "150" ></item> <item android:drawable= "@mipmap/loading_12" android:duration= "></item></" Animation-list>

My_anim.xml

<?xml version= "1.0" encoding= "Utf-8"? ><animation-list xmlns:android= "http://schemas.android.com/apk/res/ Android "android:oneshot=" false "> <item android:drawable=" @mipmap/chrysanthemum_1 "android:duration=" 150 " ></item> <item android:drawable= "@mipmap/chrysanthemum_2" android:duration= "></item> < Item android:drawable= "@mipmap/chrysanthemum_3" android:duration= "></item> <item android:drawable= "@mipmap/chrysanthemum_4" android:duration= "></item> <item android:drawable=" @mipmap/ Chrysanthemum_5 "android:duration=" ></item> <item android:drawable= "@mipmap/chrysanthemum_6" android:duration= "></item> <item android:drawable=" @mipmap/chrysanthemum_7 "android:duration=" 150    "></item> <item android:drawable=" @mipmap/chrysanthemum_8 "android:duration=" ></item> <item android:drawable= "@mipmap/chrysanthemum_9" android:duration= "></i"tem> <item android:drawable= "@mipmap/chrysanthemum_10" android:duration= "></item> <item Andro id:drawable= "@mipmap/chrysanthemum_11" android:duration= "></item> <item android:drawable=" @mipmap /chrysanthemum_12 "android:duration=" ></item></animation-list>


Mainactivity:

Package Com.example.administrator.progressdialog;import Android.app.activity;import Android.os.bundle;import Android.view.view;public class Mainactivity extends Activity {    private commprogressdialog progressdialog=null;    @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.activity_main);        Findviewbyid (r.id.bt_show). Setonclicklistener (New View.onclicklistener () {            @Override public            void OnClick ( View v) {                if (ProgressDialog = = null) {                    ProgressDialog = Commprogressdialog.createdialog (Mainactivity.this, R.anim.my_anim);                }                Progressdialog.setmessage ("Loading ...");                Progressdialog.show ();}}        );}    }



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Custom Transparent Background ProgressDialog

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.