How to make Custom Dialog look like Alert Dialog?

I created my own (custom) dialog. But I would like to have my own style, like the original Alert Dialog . That is, with a dark header background and a gray button background at the bottom. Is there any ready-to-use xml with the same? (so I wouldn't worry about the exact colors, heights, font sizes, etc.)

+4
source share
2 answers

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> 

Then it can be applied in XML layout or Android manifests, as here :

 <activity android:theme="@android:style/Theme.Dialog.Alert"> 

Or an operation using setTheme(int) . However, this does not seem to be recommended. A simple code example shown in this error message .

+6
source

I also ran into this problem, wanted to create an Activity with the same interface as AlertDialog. It was a little difficult for me. Finally, I created a transparent activity and started to enable AlertDialog.

0
source

Source: https://habr.com/ru/post/1345461/


All Articles