10

Any idea why this doesn't create an activity that looks like a popup instead of an activity that completely fills the screen?

 <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="300dip"
              android:layout_height="120dip" 
              android:layout_marginTop="100dip">

          <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                          android:orientation="vertical"
                          android:layout_height="120dip" 
                          android:layout_width="300dip">

             <TextView android:layout_width="fill_parent" 
                       android:layout_height="wrap_content" 
                       android:text="@string/hello" />

          </RelativeLayout>
     </LinearLayout>

I assumed that I only needed to set the layout height and layout width to something other than "fill_parent", but it still shows up as a black screen that completely fills the screen.

Ultimately, I simply want to create a popup, but I do not want to use an AlertDialog. Is this possible?

Ryan Alford
  • 7,514
  • 6
  • 42
  • 56

2 Answers2

26

You must set your Activity's window to be floating. You can do this either by giving your activity the Dialog style defined by Android (android:style/Theme.Dialog), or define your own style, like this:

<style name="MyFloatingWindow">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:background">@android:color/transparent</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowNoTitle">true</item>
</style>

Then set the style on your activity in the application's Manifest.

mxk
  • 43,056
  • 28
  • 105
  • 132
0

On my phone but check this website here it shows how to use PopupWindow correctly.

Hope this helps or points you in the right direction.

Anthony Forloney
  • 90,123
  • 14
  • 117
  • 115