implement a spinning activity indicator similar to iOS in Android

后端 未结 4 790
慢半拍i
慢半拍i 2021-02-02 02:58

I am trying to implement the spinning activity similar to the the one I have placed below in Android. I believe I should use the ProgressDialog. My issue arises from how to actu

4条回答
  •  悲哀的现实
    2021-02-02 03:28

    this is how i achieve it

    here is the code

    @Override   
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DIALOG_LOADING:
            final Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent);          
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.loading);
            dialog.setCancelable(true);
            dialog.setOnCancelListener(new OnCancelListener() {             
                @Override
                public void onCancel(DialogInterface dialog) {
                    //onBackPressed();
                }
            });
        return dialog;  
    
        default:
            return null;
        }
    };
    

    here is the loading.xml

    
    
     
    
    

    call the dialog with

    showDialog(DIALOG_LOADING);
    

    hide it using

    dismissDialog(DIALOG_LOADING);
    

    UPDATE

    if you want and custom indicator you can do the following in the layout.xml.

    1. replace the ProgressBar with an ImageView
    2. set the background of the ImageView to a AnimationDrawable
    3. you can start the animation in onPrepareDialog

提交回复
热议问题