Create dialog in ActionBarActivity

不问归期 提交于 2019-12-12 01:43:27

问题


I have an activity which extends from ActonBarActivity from the support library.

Now I want to add a dialog in this activity, and following the guide it seems that I have to use the DialogFragment as the dialog container:

These classes define the style and structure for your dialog, but you should use a DialogFragment as a container for your dialog. The DialogFragment class provides all the controls you need to create your dialog and manage its appearance, instead of calling methods on the Dialog object.

Then there is no way to make my activity extends DialogFragment.

And I know the Activity itself own a onCreateDialog(int id) method, but it is deprecated, I wonder what's the alternative?


回答1:


You should create a new class that extends DialogFragment, override its onCreateDialog() method with the code that creates an AlertDialog, and then instantiate that class inside your Activity and call show() on it to make it appear.



来源:https://stackoverflow.com/questions/20159389/create-dialog-in-actionbaractivity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!