how can I add a new dialog with new layout on the currently running activity without making changes to the layout file of currently running activity. I cannot add a new activity as the old activity should remain active while the new dialog is displayed.
Asked
Active
Viewed 41 times
1
-
1Create a `Dialog` and set a `View` on it? Not really sure where your problem is – codeMagic Apr 01 '14 at 02:05
-
I am a noob and don't know much. Thank you for your comment. I will try to google about the things you mentioned :) – anuj Apr 01 '14 at 02:07
-
http://androidexample.com/Custom_Dialog_-_Android_Example/index.php?view=article_discription&aid=88&aaid=111. Refer this site it will help you – Arun Antoney Apr 01 '14 at 02:38
-
@ArunAntoney is there a way to not blur the background when the dialog comes. Currently my background gets blur when the dialog comes – anuj Apr 01 '14 at 17:58
1 Answers
2
Here is a small snippet to get started on creating a Dialog
and applying a layout file to it.
// create an instance of Dialog
Dialog dialog= new Dialog(c, R.style.CustDialog);
//inflate a layout
LayoutInflater inflater = this.getLayoutInflater();
View root = inflater.inflate(R.layout.custom_alert, null);
// set the layout for the Dialog
dialog.setContentView(root);
If you read the Dialog Docs it gives the different methods you can use.
Note the docs say
The Dialog class is the base class for dialogs, but you should avoid instantiating Dialog directly. Instead, use one of the following subclasses:
So for this reason you may want to look at AlertDialog which you can find plenty of examples of on SO or the Google.
This answer gives an example of creating a custom Dialog
class.
-
yeah I got it working thank you :) Earlier I had tried to google but as I have just started android I didn't even knew what to google and had no time to start learning android from scratch – anuj Apr 01 '14 at 10:55
-
In http://www.mkyong.com/android/android-custom-dialog-example/ the background gets blur when the dialog comes, is there a way to stop that from happening? – anuj Apr 01 '14 at 18:00
-
1I don't know off-hand but typically that's what you want so the `Dialog` sticks out. You might try [PopUpWindow](http://developer.android.com/reference/android/widget/PopupWindow.html). I use that and the `Activity` doesn't dim – codeMagic Apr 01 '14 at 18:07
-