Custom progressdialog to improve user experience
Custom progressdialog to improve user experience
:
Specific implementation methods:
1. Define the Layout of Dialog
2. Set the animation anim
3. Create a custom dialog Style
4. Create a common method to control the Dialog
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PHN0cm9uZz4xPC9zdHJvbmc + placement = "brush: java;">
2. Set the animation anim: Create the anim directory loading_animation.xml
3. Create a custom dialog style Theme: values directory themes. xml
4. Create a common method to control the Dialog
/*** Get the custom progressDialog * @ param context * @ return */public static Dialog createLoadingDialog (Context context) {LayoutInflater inflater = LayoutInflater. from (context); View v = inflater. inflate (R. layout. layout_loading_dialog, null); // obtain the value of loading view LinearLayout = (LinearLayout) v. findViewById (R. id. dialog_view); // load the layout ImageView spaceshipImage = (ImageView) v. findViewById (R. id. img); Animation hyperspaceJumpAnimation = AnimationUtils. loadAnimation (context, R. anim. loading_animation); // load the animation spaceshipImage. startAnimation (hyperspaceJumpAnimation); // use ImageView to display the animation Dialog loadingDialog = new Dialog (context, R. style. loading_dialog); // create a custom Style dialog // loadingDialog. setCancelable (false); // The "Return key" cannot be used to cancel loadingDialog. setContentView (layout, new LinearLayout. layoutParams (LinearLayout. layoutParams. WRAP_CONTENT, LinearLayout. layoutParams. WRAP_CONTENT); return loadingDialog ;}
OK! You can directly call it when using it: public Dialog mLoading; mLoading = DialogUtils. createLoadingDialog (this); mLoading. show (); mLoading. dismiss ();