Reaching modal view function in Android

My goal is to install a modal view in an Android app. I would like to open one view whose background will be transparent so that the user can see the view behind.

  • I heard about using transparent activity, but it can freeze activity, right?
  • I would like some reusable types, as this view will trigger more than one action.

thanks

+4
source share
2 answers

You can do a transparent activity using this style:

<style name="TransparentActivity" parent="android:Theme.Black.NoTitleBar.Fullscreen"> <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> 

Declared in the manifest like this:

  <activity android:label="@string/app_name" android:name=".activity.DialogActivity" android:theme="@style/TransparentActivity" > 

Then I use this as a layout for my dialog:

 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/containerPageContainer"> <FrameLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:background="@drawable/panel_picture_frame_bg_focus_blue" android:layout_gravity="center" android:id="@+id/dialog"/> </FrameLayout> 

You can inflate other layouts and add them to @+id/dialog or use snippets (depending on how brave you are).

Hope this helps!

+2
source

Perhaps you could use Dialog ? You can use custom content to display whatever you want and use setCancelable(false) .

+1
source

Source: https://habr.com/ru/post/1383652/


All Articles