Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Activity that does not fill the parent screen

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?

like image 409
Ryan Alford Avatar asked Dec 14 '09 21:12

Ryan Alford


1 Answers

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.

like image 155
Matthias Avatar answered Oct 19 '22 19:10

Matthias