Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity with transparent background

what I want to achieve is activity with dialog-like transparency with 100% visibility of RelativeLayout content. This is activity's xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="50dip"
        android:layout_marginLeft="8dip"
        android:layout_marginRight="8dip"
        android:layout_marginTop="50dip">
        (...)
    </RelativeLayout>
</LinearLayout>

and this is manifest:

<activity
        android:name="com.acentic.rcontrol.activities.MyActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" >
</activity>

Right now background is still visible, what am I doing wrong?

--- EDIT: I added

android:background="#c0000000"

to LinearLayout. Now background is transparent as I wanted to, but also TextViews inside RelativeLayout are also transparent.. how to change it?

like image 667
Mariusz Avatar asked Jul 09 '13 07:07

Mariusz


People also ask

What is transparent activity?

In Android, we can create a transparent activity that will not be visible but your application will be running. The best part of this transparent activity is that you can create a transparent activity by just changing the resource file and we need not write the java or kotlin code for the same.

What is Windowistranslucent?

You could make an Activity float on the other Activities with a translucent window background, e.g. PicCollage app. That provides the end users with a visually-pleasing UX.


1 Answers

Try to set

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

in your activity.

You can also try to do this in a style:

 <style name="AppTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
</style>
like image 144
sweggersen Avatar answered Sep 19 '22 17:09

sweggersen