I have an Activity named whereActity
which has child dialogs as well. Now, I want to display this activity as a dialog for another activity.
How can I do that?
I have an Activity named whereActity
which has child dialogs as well. Now, I want to display this activity as a dialog for another activity.
How can I do that?
1 - You can use the same activity as both dialog and full screen, dynamically:
Call
setTheme(android.R.style.Theme_Dialog)
before callingsetContentView(...)
andsuper.oncreate()
in your Activity.2 - If you don't plan to change the activity theme style you can use
(as mentioned by @faisal khan)
Set the theme in your android manifest file.
And set the dialog state on touch to finish.
You can define this style in values/styles.xml to perform a more former Splash :
And use it AndroidManifest.xml:
If you need Appcompat Version
style.xml
yourmanifest.xml
If you want to remove activity header & provide a custom view for the dialog add the following to the activity block of you manifest
and design your activity_layout with your desired view
To start activity as dialog I defined it like this in
AndroidManifest.xml
:Use this property inside your
activity
tag to avoid that your Dialog appears in the recently used apps listIf you want to stop your dialog / activity from being destroyed when the user clicks outside of the dialog:
After
setContentView()
in yourActivity
use:this.setFinishOnTouchOutside(false);
Now when I call
startActivity()
it displays as a dialog, with the previous activity shown when the user presses the back button.Note that if you are using
ActionBarActivity
(or AppCompat theme), you'll need to use@style/Theme.AppCompat.Dialog
instead.