Skip to content

Instantly share code, notes, and snippets.

@sandeepyohans
Created September 19, 2019 09:40
Show Gist options
  • Save sandeepyohans/bf95616054c27ef1d8c609de32f08bb9 to your computer and use it in GitHub Desktop.
Save sandeepyohans/bf95616054c27ef1d8c609de32f08bb9 to your computer and use it in GitHub Desktop.
Utility method to display AlertDialog with ProgressBar in Android
public AlertDialog.Builder getDialogProgressBar() {
AlertDialog.Builder builder = new AlertDialog.Builder(Objects.requireNonNull(getContext()));
builder.setTitle("Loading...");
builder.setCancelable(false);
final ProgressBar progressBar = new ProgressBar(getContext());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
progressBar.setLayoutParams(lp);
builder.setView(progressBar);
// builder.setPositiveButton("OK",
// (dialogInterface, i) -> Toast.makeText(getApplicationContext(),
// "Text entered is " + input.getText().toString(),
// Toast.LENGTH_SHORT).show());
return builder;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment