Created
July 9, 2012 19:11
-
-
Save aleksi-niiranen/3078300 to your computer and use it in GitHub Desktop.
Loading view popup in Android
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
<!-- 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> |
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
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