3

I want my activity to appear like a big form of dialog, something which is transparent say a quarter on all the four sides and the middle part is solid where I can place the views. I thought using Frame Layout would be the answer by placing a frame layout inside another,but I am unable to make the first one transparent.

My XML file:-

<?xml version="1.0" encoding="utf-8"?>


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000" >

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="50dp"
        android:layout_marginLeft="75dp"
        android:layout_marginRight="75dp"
        android:layout_marginTop="50dp" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:text="Search" />

            <EditText
                android:id="@+id/editText1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/button1"
                android:layout_alignParentLeft="true"
                android:layout_marginBottom="30dp"
                android:gravity="center"
                android:hint="Enter Movie Name!" />

            <ProgressBar
                android:id="@+id/progressBar1"
                style="?android:attr/progressBarStyleLarge"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/editText1"
                android:layout_centerHorizontal="true" />

        </RelativeLayout>

    </FrameLayout>


</FrameLayout>

Its not working. Any Ideas?

Mohit
  • 1,045
  • 4
  • 18
  • 45

2 Answers2

1

I had the same problem. I solved it by using:

getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

I don't know why it only works programmatically.

Found this here (at the end).

Community
  • 1
  • 1
punchlag
  • 238
  • 2
  • 6
0

You have to set that activity's theme like this:

Manifest.xml

    <activity
        android:name=".activity.ImagePreviewActivity"
        android:theme="@style/Theme.Transparent"/>

in res/values/styles.xml

<style name="Theme.Transparent" parent="Theme.MCChilli.NoTitle">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

Also, I think this answer is just a few google clicks away but whatever...

dominik4142
  • 556
  • 3
  • 14
  • Wouldn't this make the whole activity transparent, I just want a part to be transparent. – Mohit Oct 17 '14 at 16:17
  • Isnt it what you want? 'I want my activity to appear like a big form of dialog'?! – dominik4142 Oct 17 '14 at 16:20
  • Well a dialog is solid in middle and the we can see the backgroung on all four sides, your code is making the whole activity transparent – Mohit Oct 17 '14 at 16:23
  • Ok, in that case you should try it. Ever wondered what would be a usage of totally transparent activity? Of course you have to supply contentView to ImagePreviewActivity, otherwise it will be EMPTY, not transparent everywhere. – dominik4142 Oct 17 '14 at 16:27
  • @Mohit http://stackoverflow.com/questions/2176922/how-to-create-transparent-activity-in-android – dominik4142 Oct 17 '14 at 16:28