Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show translucent activity?

How can I create a translucent activity on top of my activity to show help contents? I've seen many apps showing help content over a translucent screen(like when a spinner dropdown is shown, the rest of the screen goes dim and the drop down is projected. I want to create that dim screen)

like image 943
Sachin Murali G Avatar asked Dec 20 '22 20:12

Sachin Murali G


2 Answers

Just set the appropriate theme to your activity in your AndroidManifest.xml:

<activity android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">

You could set the theme in onCreate() of your activity, but you will see a black flickering for the time between the setup of the activity.

like image 115
flx Avatar answered Jan 16 '23 06:01

flx


Declare your activity in manifest like this:

<activity android:name=".yourActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>

and add a transparent background to your layout.

To avoid black flickering you should disable activity animation by creating a style:

<style name="noAnimTheme" parent="android:Theme">
  <item name="android:windowAnimationStyle">@null</item>
</style>

then in manifest set it as theme for activity or whole application.

<activity android:name=".ui.yourActivity" android:theme="@style/noAnimTheme">
</activity>

Or just specify Intent.FLAG_ACTIVITY_NO_ANIMATION flag when starting activity.

like image 36
Plo_Koon Avatar answered Jan 16 '23 07:01

Plo_Koon