32

マテリアル ガイドラインでは、フルスクリーン ダイアログの動作について説明します。

全画面ダイアログ | ダイアログ - マテリアル デザイン

実際にこれを達成するにはどうすればよいですか?

4

3 に答える 3

5

使用するDialogFragment

ダイアログをフルスクリーンで表示する、または埋め込みフラグメントとして表示するには、このリンクを参照してください

http://developer.android.com/guide/topics/ui/dialogs.html#FullscreenDialog

ここにコードをコピーするだけです。

ダイアログフラグメントを作成する

    public class CustomDialogFragment extends DialogFragment {
    /** The system calls this to get the DialogFragment's layout, regardless
        of whether it's being displayed as a dialog or an embedded fragment. */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Inflate the layout to use as dialog or embedded fragment
        return inflater.inflate(R.layout.purchase_items, container, false);
    }

    /** The system calls this only when creating the layout in a dialog. */
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // The only reason you might override this method when using onCreateView() is
        // to modify any dialog characteristics. For example, the dialog includes a
        // title by default, but your custom layout might not need it. So here you can
        // remove the dialog title, but you must call the superclass to get the Dialog.
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        return dialog;
    }
}

次に、このメソッドを追加してダイアログを表示します

    public void showDialog() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    CustomDialogFragment newFragment = new CustomDialogFragment();

    if (mIsLargeLayout) {
        // The device is using a large layout, so show the fragment as a dialog
        newFragment.show(fragmentManager, "dialog");
    } else {
        // The device is smaller, so show the fragment fullscreen
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        // For a little polish, specify a transition animation
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        // To make it fullscreen, use the 'content' root view as the container
        // for the fragment, which is always the root view for the activity
        transaction.add(android.R.id.content, newFragment)
                   .addToBackStack(null).commit();
    }
}

焦点を当てなければならない主なものは、この行にあります

transaction.add(android.R.id.content, newFragment).addToBackStack(null).commit();

rootview をandroid.R.id.contentとして指定すると、ダイアログが全画面表示になります

于 2015-07-24T09:36:55.957 に答える
0

このコードを試してください:

Dialog yourDialog=new Dialog(this,android.R.styleTheme_Black_NoTitleBar_Fullscreen)
于 2015-07-24T09:33:39.613 に答える