Android PopUp Floating Window Tutorial

Android has a PopupWindow object to implements floating windows in the activity to display information or perform some action. It is very convenient when its come to some situation like give the user an extra window to interact with your app. You can customize your popup window in which you wanna display on that window. In this tutorial, I will let you understand how the android popup floating window work in the android application.

PopUp Floating Window Sample Screen

sample popup floating window screen

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “FloatingWindowExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Activity” and Click Next button
5. Lastly, press finish button.

Add a new custom popupwindow xml

In the res>layout and right click create a new layout name “popup”, after that follow the source code in the below section.

Edit activity_main.xml

Go to the activity_main.xml and add one button to display the floating button on your screen.

Edit class

After that, go to the mainactivity class and add the button listener to add the window in the screen and also set touch listener to drag the windows on the screen.

Run Your Project

In conclusion, you are successfully implement a popupwindow in your android project. Now you can test it out in your device.

(Android PopUp Floating Window)

Source Code

(Visited 11,205 times, 1 visits today)

Yong Loon Ng

Ng Yong Loon, better known as Kristofer is a software engineer and computer scientist who doubles up as an entrepreneur.

You may also like...

3 Responses

  1. inon says:


    I tried to implement this popup as you did exactly.
    my app falls at this line:
    ——> popupView = layoutInflater.inflate(R.layout.popup,null);
    Do you know why? or how can i figure it out?

  2. Daniel says:

    TKS, that works very fine. Simple and complete.
    I just made a little change.

    I moved this hole part out of the click event:
    LayoutInflater layoutInflater =(LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    popupView = layoutInflater.inflate(R.layout.popup,null);
    popupWindow = new PopupWindow(popupView, RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);

    Inside the click event, it was intancing a new popupWindow on each click, even if there was some one up. And the close button was clossing just the last instance.

  3. Mayank Choudhary says:

    VideoView Is not working in this PopUp window..??
    Nothing shows ,no any popUps.

Leave a Reply

Your email address will not be published. Required fields are marked *