Help us understand the problem. What is going on with this article?

ぱぱっと自作ローディングダイアログ

More than 3 years have passed since last update.

完成予定のダイアログ

こんな感じです!
Screenshot_2015-02-03-14-59-35.png

ActivityからDialogのインスタンスを取得出来るクラスを作成

public class Loading {
    // Dialogを返す
    public static Dialog getDialog(Activity activity){
        Dialog dialog = new Dialog(activity);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.setContentView(R.layout.simple_progress);
        return dialog;
    }
}

R.layout.simple_progressの中身(res/layout/simple_progress.xml)
ProgressBarを使い、くるくる回るやつを表示
※このくるくるのデザインは、OSや指定しているテーマに依存します。

<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/simple_progress_bar"
    android:layout_width="128dp"
    android:layout_height="128dp"
    android:layout_gravity="center"
    android:background="@drawable/simple_progress_frame"
    android:gravity="center" >

</ProgressBar>

@drawable/simple_progress_frameの中身(res/drawable/simple_progress_frame)
Shapeを使いダイアログの四隅の角丸を指定

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#80808080"/>
    <corners android:radius="16dp"/>
    <padding android:left="4dp" android:top="4dp" android:right="4dp" android:bottom="4dp" />
    <stroke android:width="0dp" android:color="#a0808080" />
</shape>

Activityからの呼び出し

public class MainActivity extends FragmentActivity {    
    private Dialog mDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        mDialog = Loading.getDialog(MainActivity.this);
        mDialog.show();
    }

    @Override
    protected void onPause(){
        super.onPause();
        if(mDialog != null && mDialog.isShowing()){
            mDialog.dismiss();
        }
    }
}

これで色んなActivityから呼べるようになります!!
mDialog.dismiss();を忘れずにー

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away