Pregunta

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

¿Fue útil?

Solución

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

Otros consejos

Change dialog theme to:

<style name="CustomDialogTheme" parent="@android:style/Theme.Dialog">
    <item name="android:windowBackground">@android:color/white</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowNoTitle">true</item>
</style>

In custom dialog when you call super call this:

public CustomDialog(Context context) {
    super(context, R.style.CustomDialogTheme);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top