In the activity you want to use fragment type :
FragmentManager fm = getSupportFragmentManager();
//fragment class name : DFragment
DFragment dFragment = new DFragment();
// Show DialogFragment
dFragment.show(fm, "Welcome to dialog fragment!!");
Now create a class DFragment and type :
public class DFragment extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.dialogfragment, container,
false);
getDialog().setTitle("DialogFragment Tutorial");
// Do something else
return rootView;
}
}
dialogfragment.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="10dp"
android:text="@string/welcome" />
</RelativeLayout>
Hope it helps!!