在ActionBarActivity创建对话框 [英] Create dialog in ActionBarActivity

查看:163
本文介绍了在ActionBarActivity创建对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 ActonBarActivity 的范围是从支持库的活动。

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

现在我想在这个活动添加一个对话框,并按照指南看来,我必须使用 DialogFragment 作为对话框容器:

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:

这些类定义为您的对话框的风格和结构,但你
  应使用DialogFragment为你的对话框的容器。该
  DialogFragment类提供您需要创建的所有控件
  对话框和管理,而不是调用方法它的外观,
  Dialog对象。

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.

那么有没有办法让我的活动来延长 DialogFragment

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

我知道了活动本身拥有 onCreateDialog(INT ID)方法,但它是德precated,我不知道有什么别的选择吗?

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

推荐答案

您应该创建一个新的类,它扩展了 DialogFragment ,覆盖其 onCreateDialog( )方法与code,创建一个 AlertDialog ,然后实例化活动里面的那个类和呼叫显示()上它,使之出现。

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.

这篇关于在ActionBarActivity创建对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆