I want to create a custom dialog box like below
I have tried the following things.
I created a subclass of AlertDialog.Builder and used a custom Title and Custom Content View and used that but the result was not as expected.
Another attempt was to subclass DialogFragment and customize the dialog inside onCreateDialog that but result was not as expected.
Then I tried using a plain Dialog class. The result was not as expected.
In all three cases, the problem is when I overlook the title view the size of the dialog is not as expected and when I use Title view the result is there is a thick border around the content view (which really looks bad). Now I have two questions in my mind...
How can I achieve that? As I have already tried so many things, a direct answer will be more appreciated.
What is the best way to show an error or alert dialog in an android app?
EDIT Android Developer Documentation recommends that we should use either DialogFragments or Dialogs for showing Error / Alert Messages to the user. However at one point they say ...
Tip: If you want a custom dialog, you can instead display an Activity as a dialog instead of using the Dialog APIs. Simply create an activity and set its theme to Theme.Holo.Dialog in the manifest element.
What is the meaning of that? Isn't it too much to use an Activity just for showing an error message???
This is an example dialog, create with xml.
the next code xml is just an example, the design or view is implemented here:
this lines of code are resources of drawable:
you could do a class extends Dialog, also something like this:
finally the form of call, on your Activity for example:
I hope its work for you.
Add the below theme in
values -> style.xml
Use this theme in your
onCreateDialog
method like this:Define your dialog layout including title bar in the xml file and set that xml file like this:
The above screenshot is my outcome.
Steps :
Please refer the given link for code reference CustomDialogBox.