Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a transparent activity WITHOUT windowIsFloating

windowIsFloating while a great one stop shop for creating Dialog styled UI's has many ---bugs--- quirks.

The one which I'm battling right now is that it assigned the width/height of the top ancestor as "wrap_content" rather than the width/height of the screen. This means the usual UI design of using "match_parents" will propogate upwards to become "wrap_content". Bad times.

So, what I would really like is to create an activity, and have a layout like so:

<LinearLayout   android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:id="@+id/containerPageConatiner"
                android:background="@drawable/windowBackground">
    <View           android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"/>
    <FrameLayout    android:id="@+id/singlePane"
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent"
                    android:layout_gravity="center_horizontal|center_vertical"
                    android:padding="10dp"/>    
    <View           android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"/>                         
</LinearLayout> 

Which produces a UI showing a single window (@id/singlePane) ontop of the Activity which called it.

Does anybody have the just right set of styles needed to create a transparent background Activity?

like image 300
Graeme Avatar asked Oct 25 '11 11:10

Graeme


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.

Can we create activity without UI in Android?

Explanation. Generally, every activity is having its UI(Layout). But if a developer wants to create an activity without UI, he can do it.


1 Answers

Thanks to @PolamReddy who nudged me towards answer I wanted:

The theme Theme.Translucent.NoTitleBar.Fullscreen and its ancestors contains all the attributes you need to create a translucent window. In order to get everything apart from windowIsFloating I went through the ancestor stack and pulled out the entire set of attributes:

<style name="Theme.CustomTheme.TransparentActivity">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowAnimationStyle">@android:style/Animation</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowFullscreen">true</item>
</style> 

This style must be assigned to the Activity in the AndroidManifest.xml rather than the root view of a layout.

like image 133
Graeme Avatar answered Sep 21 '22 06:09

Graeme