Created
October 5, 2017 15:04
-
-
Save josemigallas/1cc03ec52af709f536c5bf4ae39c5597 to your computer and use it in GitHub Desktop.
Very cool dialog that blocks the screen, to be used during some asynchronous process preventing user from interacting with the screen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:padding="16dp"> | |
<ProgressBar | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginEnd="16dp" | |
android:layout_marginRight="16dp" | |
android:indeterminate="true" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center_vertical" | |
android:text="@string/loading" | |
android:textColor="@android:color/primary_text_light" | |
android:textSize="16sp" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Dialog; | |
import android.os.Bundle; | |
import android.support.annotation.NonNull; | |
import android.support.annotation.Nullable; | |
import android.support.v4.app.DialogFragment; | |
import android.support.v7.app.AlertDialog; | |
public class LoadingDialog extends DialogFragment { | |
private static final String ARG_TITLE = "TITLE"; | |
private String title; | |
public static LoadingDialog newInstance(String title) { | |
LoadingDialog fragment = new LoadingDialog(); | |
Bundle args = new Bundle(); | |
args.putString(ARG_TITLE, title); | |
fragment.setArguments(args); | |
return fragment; | |
} | |
public static LoadingDialog newInstance() { | |
return new LoadingDialog(); | |
} | |
public LoadingDialog() { | |
} | |
@Override | |
public void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
if (getArguments() != null) { | |
title = getArguments().getString(ARG_TITLE); | |
} | |
setCancelable(false); | |
} | |
@NonNull | |
@Override | |
public Dialog onCreateDialog(Bundle savedInstanceState) { | |
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getContext()) | |
.setView(R.layout.dialog_loading); | |
if (title != null) { | |
alertDialog.setTitle(title); | |
} | |
return alertDialog.create(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage