Android Activity as a dialog

后端 未结 10 2396
轮回少年
轮回少年 2020-11-22 02:31

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 d

10条回答
  •  既然无缘
    2020-11-22 03:10

    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 list

    android:excludeFromRecents="true"
    

    If you want to stop your dialog / activity from being destroyed when the user clicks outside of the dialog:

    After setContentView() in your Activity 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.

提交回复
热议问题