srbyk1990 srbyk1990 - 3 months ago 23
Android Question

Alert Dialog Box Theme Issue

I am getting an error when trying to set theme for alertDialogbox. I am betting white box behind the alertdialogbox. Any idea how i can get rid of it? Here is my code for styles.xml.
enter image description here

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowSoftInputMode">stateUnchanged|adjustPan</item>
<item name="android:alertDialogTheme">@style/alertTheme</item>
</style>

<style name="alertTheme" parent="@android:style/Theme.Holo.Light.Dialog">
</style>

Answer

In your values res folder, your alertDialogTheme should have the following property:

<!-- In API <21, this gives a funky background. Set to translucent --> <item name="android:windowBackground">@color/translucent</item>

where @color/translucent is defined in colors.xml as #00000000, which gives opacity of 0.

In your values-v21 res folder, your alertDialogTheme should have the following property:

<!-- In API 21+, this is the dialog background color --> <item name="android:windowBackground">@color/someColor</item>

This does nothing to alertDialogs in any API as far as I can tell:

<!--<item name="android:colorBackground">...</item>-->

I've only tested this on the Light AppCompat theme.

Comments