首先定义一个xml布局findupdatefragment.xml表明对话框的界面。
新建继承了dialogfragment类的一个类,重写方法:
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) { getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);//设置对话框无标题 getDialog().getWindow().setBackgroundDrawableResource(android.R.color.transparent);//设置对话框无背景 View view = inflater.inflate(R.layout.findupdatefragment,container,false);//第一个参数就是对话框的界面布局id return view; }
在主方法中调用:
public void showFindUpdateFragment(){ findUpdateFragment findUpdateFragment = new findUpdateFragment(); findUpdateFragment.show(getFragmentManager(), "findUpdateFragment"); }