Skip to content

Instantly share code, notes, and snippets.

@aleksi-niiranen
Created July 9, 2012 19:11
Show Gist options
  • Save aleksi-niiranen/3078300 to your computer and use it in GitHub Desktop.
Save aleksi-niiranen/3078300 to your computer and use it in GitHub Desktop.
Loading view popup in Android
<!-- layout file for loading view : indeterminate_progress.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="@color/progress_popup_background" >
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- colors.xml -->
<resources>
<!-- first two numbers are alpha channel to make the popup slightly transparent -->
<color name="progress_popup_background">#80eeeeee</color>
</resources>
public class SomeActivity extends Activity {
// make it a field so we can dismiss it when the activity pauses.
// otherwise the window will leak and cause and exception when the activity no longer exists
private PopupWindow mPopup;
public void showPopup() {
View popupView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.indeterminate_progress, null);
Display display = getWindowManager().getDefaultDisplay();
// getWidth() and getHeight() are deprecated and we should use getSize() but it's available on API level 13 and up
mPopup = new PopupWindow(popupView, display.getWidth(), display.getHeight());
// rootView here is the root view of the activity's layout
mPopup.showAtLocation(findViewById(R.id.rootView), Gravity.CENTER, 0, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment