Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Android Theme.Light for Alert Dialog

I am trying to set the android Theme.Light theme for my alert dialog, but with no success so far. After reading a few tutorials I gathered that using AlertDialog.Builder we cannot set the theme directly in the constructor (atleast in API level 7).

The alternate solution that I found is using a ContextThemeWrapper, which everyone assured would solve my problem. So I coded something like this:

AlertDialog.Builder builder = new AlertDialog.Builder(                     new ContextThemeWrapper(context, R.style.popup_theme)); 

I described my theme in the values folder:

<?xml version="1.0" encoding="utf-8"?> <resources> <color name="back_color">#ffffffff</color> <style name="popup_theme" parent="@android:style/Theme.Light">     <item name="android:windowBackground">@color/back_color</item>     <item name="android:colorBackground">@color/back_color</item> </style> 

Unfortunately I still get the default Theme.Dialog.Alert theme. Can anyone tell me why? Where am I going wrong?

EDIT: If you do not know the answer to my question, please vote up. I have a bad habit of posting questions which get stuck :(

like image 735
Arnab Chakraborty Avatar asked Jul 18 '11 07:07

Arnab Chakraborty


People also ask

How do I customize alert dialog?

Add custom_layout. xml in that activity in which you want to show custom alert dialog here it is added in MainActivity. java.

How do I change the background color of alert in dialog?

You should use the android:windowBackground theme attribute instead. android:background will change the background color of every View . Actually, both background and windowBackground remove rounded corners from the dialog window. If you want to set a color, you should use colorBackground attribute instead.

How many styles of AlertDialog are there?

There are three kinds of lists available with the AlertDialog APIs: A traditional single-choice list. A persistent single-choice list (radio buttons) A persistent multiple-choice list (checkboxes)


1 Answers

change parent="android:Theme.Light" to parent="@android:style/Theme.Light"

like image 170
Gallal Avatar answered Sep 17 '22 17:09

Gallal