I've created my own (custom) Dialog. But would like to have its style like original Alert Dialog. I.e. with dark title background and grey buttons background on the bottom. Is there any ready-for-use xml with the same? (so, I wouldn't worry about exact colors, heights, font sizes etc.)
Asked
Active
Viewed 8,076 times
2 Answers
6
This answer is incorrect
Use Theme.Dialog.Alert
From themes.xml:
<!-- Default theme for alert dialog windows, which is used by the
{@link android.app.AlertDialog} class. This is basically a dialog
but sets the background to empty so it can do two-tone backgrounds. -->
<style name="Theme.Dialog.Alert" parent="@android:style/Theme.Dialog">
<item name="windowBackground">@android:color/transparent</item>
<item name="windowTitleStyle">@android:style/DialogWindowTitle</item>
<item name="windowIsFloating">true</item>
<item name="windowContentOverlay">@null</item>
</style>
This can then be applied within an XML layout or Android manifest, as referenced here:
<activity android:theme="@android:style/Theme.Dialog.Alert">
Or onto an Activity using setTheme(int)
. However, this does not seem to be a recommended practice. Simple sample code shown in this bug report.

Kyle Ivey
- 5,992
- 1
- 23
- 35
-
1Thanks, @Karl. How can I apply that to my own dialog? – LA_ Mar 28 '11 at 06:09
-
That depends on how you have defined your dialog - either by within XML or programmatically. Programmatic application of themes seems to not be recommended. I've updated my answer slightly. Also see this link: http://www.anddev.org/applying_a_theme_to_your_application-t817.html – Kyle Ivey Mar 28 '11 at 08:01
-
My answer is incorrect. Testing, I see that Theme.Dialog.Alert is not even public. It's only used by the AlertDialog class as a simple template. The real styling is later hard-coded within the class. Sorry. – Kyle Ivey Mar 28 '11 at 18:39
-
What else I can try then? How to read these standard colors/field heights to apply them to my dialog? – LA_ Apr 02 '11 at 12:35
-
You will have to style the dialog yourself. Within [themes.xml](http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/themes.xml) is the section for ` – Kyle Ivey Apr 06 '11 at 19:30