fragmentdialog动画及宽高

package com.vortex.attendance.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentTransaction;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.vortex.reportanddispatch.R;

/**
 * Created by Administrator (chenPS) on 2019/12/18.
 */
public class SingleButtonDialog extends DialogFragment {

    private String contentStr;
    private String btnStr;

    public static SingleButtonDialog getInstance(String contentStr, String buttonStr) {
        SingleButtonDialog dialog = new SingleButtonDialog();
        Bundle bundle = new Bundle();
        bundle.putString("contentStr", contentStr);
        bundle.putString("btnStr", buttonStr);
        dialog.setArguments(bundle);
        return dialog;
    }


    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = new Dialog(getContext());
        View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_single_button_tips, null);
        TextView contentTv = view.findViewById(R.id.d_s_b_tips_content_tv);
        TextView submitBtn = view.findViewById(R.id.d_s_b_tips_submit_btn);
        Bundle bundle = getArguments();
        contentStr = bundle.getString("contentStr", "有新的提示信息");
        btnStr = bundle.getString("btnStr", "确认");
        contentTv.setText(contentStr);
        submitBtn.setText(btnStr);
        dialog.setContentView(view);
        submitBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Activity parent = getActivity();
                if (parent instanceof onButtonClickListener) {
                    ((onButtonClickListener) parent).onSubmitClick(getTag());
                }
                dismiss();
            }
        });
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        dialog.getWindow().setLayout((int) (dm.widthPixels * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT);
        Window window = dialog.getWindow();
        window.setWindowAnimations(R.style.DialogAnimation);
        return dialog;
    }


    public interface onButtonClickListener {
        void onSubmitClick(String tag);
    }

    @Override
    public void onStart() {
        super.onStart();


    }

    @Override
    public int show(FragmentTransaction transaction, String tag) {
        return super.show(transaction, tag);
    }
}

  

package com.vortex.attendance.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

import com.vortex.reportanddispatch.R;

/**
 * Created by Administrator (chenPS) on 2019/12/18.
*一般设置dialog全屏的话 要自定义下 style 不然会有一个padding 设置matchparent 也不会等于屏幕宽度
 */
public class SelectPicDialog extends DialogFragment {


    public static SelectPicDialog getInstance() {
        SelectPicDialog dialog = new SelectPicDialog();
        return dialog;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = new Dialog(getContext(),R.style.CommonDialog2);
        View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_select_pic_mode, null);
        ImageView cameraIv = view.findViewById(R.id.d_s_p_mode_camera_iv);
        ImageView galleryIv = view.findViewById(R.id.d_s_p_mode_gallery_iv);
        dialog.setContentView(view);
//        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//        dialog.getWindow().setWindowAnimations(R.style.DialogAnimationBottom);
        WindowManager.LayoutParams layoutParams=dialog.getWindow().getAttributes();
        layoutParams.gravity= Gravity.BOTTOM;
        layoutParams.width= WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height=WindowManager.LayoutParams.WRAP_CONTENT;
        layoutParams.windowAnimations=R.style.DialogAnimationBottom;
        dialog.getWindow().setAttributes(layoutParams);
        final Activity parent = getActivity();
        cameraIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (parent instanceof onChoiceListener) {
                    ((onChoiceListener) parent).onCameraChoice(getTag());
                }
                dismiss();
            }
        });
        galleryIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (parent instanceof onChoiceListener) {
                    ((onChoiceListener) parent).onGalleryChoice(getTag());
                }
                dismiss();
            }
        });
        return dialog;
    }

    public interface onChoiceListener {
        void onCameraChoice(String tag);

        void onGalleryChoice(String tag);
    }


}

 

你可能感兴趣的:(fragmentdialog动画及宽高)