DialogFragment 对话框 碎片


package com.example.m_evolution; import android.app.Dialog; import android.app.DialogFragment; import android.media.MediaPlayer; import android.os.Bundle; import android.os.Handler; import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; import android.view.View; import android.view.WindowManager; import android.widget.SeekBar; import android.widget.TextView; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.TimeUnit; import com.melnykov.fab.FloatingActionButton; public class ReplayRecordDialogFragment extends DialogFragment { public static ReplayRecordDialogFragment newInstance(String file_name) { ReplayRecordDialogFragment dialogFragment = new ReplayRecordDialogFragment(); Bundle bundle = new Bundle(); bundle.putString(FILE_NAME, file_name); dialogFragment.setArguments(bundle); return dialogFragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { file_name = getArguments().getString(FILE_NAME); } } @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_replayrecord, null); builder.setView(view); return builder.create(); } }

使用起来与Fragment很相像

在Activity使用时:

ReplayRecordDialogFragment fragmentReplay = ReplayRecordDialogFragment.newInstance(filename_record);
fragmentReplay.show(getFragmentManager(), ReplayRecordDialogFragment.class.getSimpleName());

 

上一篇:android – 从扩展RecyclerView.ViewHolder的类开始DialogFragment


下一篇:解决 IE6 position:fixed 固定定位问题