我们也可以创建DialogFragment。顾名思义,DialogFragment就是一个浮动在Activity上面的 Fragment。当需要用户的反馈时,DialogFragment就会派上用场。与使用ListFragment类似,需要继承 DialogFragment基类。
下面将会展示如何使用DialogFragment。
public class Progr
essDialogFragment extends DialogFragment { private static final String EXTRA_MESSAGE = "message"; public static ProgressDialogFragment newInstance(String message) { Bundle bundle = new Bundle(); bundle.putString(EXTRA_MESSAGE, message); ProgressDialogFragment f = new ProgressDialogFragment(); f.setArguments(bundle); return f; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { String message = getArguments().getString(EXTRA_MESSAGE); ProgressDialog dialog = new ProgressDialog(getActivity()); dialog.setIndeterminate(true); dialog.setMessage(message); return dialog; }}
效果如下:
转载于:https://www.cnblogs.com/summerful/archive/2012/12/10/2811678.html