Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Dialog - Custom background instead of dimming or blurring

I have created my own custom dialog and it works fine but I want to change dimmed background to a custom pattern (for example an image file or a xml shape). How can I achieve that?
Note that I do not want to change intensity of dimming but I just want, this dimming be replaced with a pattern

like image 658
frogatto Avatar asked Oct 20 '22 16:10

frogatto


1 Answers

I found a workaround for this problem, I derived this from @vipul mittal answer,
I should set dialog theme as following:

<item name="android:windowIsFloating">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>

With this theme my dialog will be:

  • full screen because windowIsFloating is set to false
  • surrounding area is fully transparent because windowBackground is set to @android:color/transparent

Now I should wrap my dialog xml layout contents with a wrapper that plays surrounding area role, in this case I have picked FrameLayout for this:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/dialog_back"> <!-- this is surrounding area drawable -->

    <!-- dialog contents goes here -->

</FrameLayout>

Here is a screenshot of my final dialog:
enter image description here

like image 143
frogatto Avatar answered Jan 02 '23 20:01

frogatto