Custom load pop-up windows

Source: Internet
Author: User

When Android data is loaded, it often takes a waiting pop-up window. While the system comes with pop-up style often and our software does not want to conform to these records, a simple custom style loading wait box. (All the footage I'll be sharing with you)

First on

1. Create a new custom layout style loading_dialog.xml.

1<?xml version= "1.0" encoding= "Utf-8"?>2<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"3Android:id= "@+id/dialog_view"4android:orientation= "Vertical"5Android:layout_width= "Match_parent"6android:layout_height= "Match_parent"7android:minheight= "80DP"8Android:minwidth= "200DP"9android:gravity= "Center"Tenandroid:background= "@drawable/corners_5" Oneandroid:padding= "10DP" > A<ImageView -Android:id= "@+id/img" -Android:layout_width= "Wrap_content" theandroid:layout_height= "Wrap_content" -android:src= "@drawable/ll_loading_outside" -Android:layout_marginbottom= "10DP" -/> +<TextView -Android:id= "@+id/tiptextview" +Android:layout_width= "Wrap_content" Aandroid:layout_height= "Wrap_content" atandroid:text= "Data Loading ..."/> -</LinearLayout>
View Code

2. New style properties file Corners_5.xml.

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" >    <!--fill-    <solid android:color= "#fff"/>    <!--margins--    <Corners        Android:topleftradius= "5DP"        android:toprightradius= "5DP"        Android:bottomleftradius = "5DP"        android:bottomrightradius= "5DP"/></shape>
View Code

3. Add a custom style under Styles.xml

    <!--Custom Loading dialog-    <style name= "Loading_dialog" parent= "Android:style/theme.dialog" >        <item name= "Android:windowframe" >@null</item>        <item name= "Android:windownotitle" > true</item>        <item name= "Android:windowbackground" > @color/colorempty</item>        <item name= "Android:windowisfloating" >true</item>        <item name= "Android: Windowcontentoverlay ">@null</item>    </style>
View Code

4. Define a blank color style in Colors.xml

<color name= "Colorempty" > #00000000 </color><!--Transparent--
View Code

5. Create a new folder under the Res folder Anim and create a new pop-up animation effect under the folder Loadingdialog_anim.xml

<?xml version= "1.0" encoding= "Utf-8"? ><set android:shareinterpolator= "false" xmlns:android= "/HTTP/ Schemas.android.com/apk/res/android ">    <rotate        android:interpolator=" @android: anim/ Linear_interpolator "        android:pivotx=" 50% "        android:pivoty=" 50% "        android: Fromdegrees= "0"        android:todegrees= "+360"        android:duration= "         the" Android:startoffset= "-1"        android:repeatmode= "Restart"        android:repeatcount 
View Code

6, below we customize a helper class Loadingdialog.

 Packageuntil;ImportAndroid.app.Dialog;ImportAndroid.content.Context;ImportAndroid.view.LayoutInflater;ImportAndroid.view.View;Importandroid.view.animation.Animation;Importandroid.view.animation.AnimationUtils;ImportAndroid.widget.ImageView;Importandroid.widget.LinearLayout;ImportAndroid.widget.TextView;ImportCOM.LYF.NET.R;/*** Lyf on 2016/5/14. * Show waiting pop-up window*/ Public classLoadingdialog { Public StaticDialog getloadingdialog (Context context,string msg) {layoutinflater Inflater=Layoutinflater.from (context); View v= Inflater.inflate (R.layout.loading_dialog,NULL);//Get load ViewLinearLayout layout = (linearlayout) V.findviewbyid (R.id.dialog_view);//Loading Layouts//the ImageView in Main.xmlImageView Spaceshipimage =(ImageView) V.findviewbyid (r.id.img); TextView Tiptextview= (TextView) V.findviewbyid (R.id.tiptextview);//hint Text//Loading AnimationsAnimation hyperspacejumpanimation =animationutils.loadanimation (context, R.anim.loadingdialog_anim); //display animations using ImageViewspaceshipimage.startanimation (hyperspacejumpanimation); Tiptextview.settext (msg);//Setting Load InformationDialog Loadingdialog=NewDialog (context, r.style.loading_dialog);//Create a custom style dialogloadingdialog.setcancelable (false);//can not be canceled with "Return key"Loadingdialog.setcontentview (Layout,Newlinearlayout.layoutparams (LinearLayout.LayoutParams.MATCH_PARENT, LINEARLAYOUT.LAYOUTP Arams. match_parent));//Set Layout        returnLoadingdialog; }}
View Code

So our custom dialog pop-up window is over, and here's the call.

Dialog PD = Loadingdialog.getloadingdialog (Addxf_infoactivity.this, "Loading ...");
Pd.show ();

Shut down

Pd.dismiss ();

Material: Https://yunpan.cn/cSZ58jgIGcGXH access password a13e.


Custom load pop-up windows

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.