Android PopupWindow Example

Here you will get Android PopupWindow example code.

Popup window is a floating view that is displayed on top of an activity. Android provides PopupWindow class for creating a popup window with custom design. Below I have shared code to create simple popup window in android with a text and button to close it.

Android PopupWindow Example

Create an android project with package name com.popupwindow. Add following code in respective files.

res/layout/activity_main.xml

res/layout/popup.xml

MainActivity.java

The code is self explanatory as I have added comments wherever required. Save and run the project.

Android PopupWindow Example

Comment below if you have any queries regarding above android popup window example.

4 thoughts on “Android PopupWindow Example”

  1. When I am following this process, I am getting “android.view.WindowManager$BadTokenException: Unable to add window — token null is not valid; is your activity running?” error any comments on this?

  2. error: ‘;’ expected protected void onCreate(Bundle savedInstanceState)
    I’m getting this error, I checked all the “{” and “;” in my code.
    any suggestion?

Leave a Comment

Your email address will not be published.