自定义dialog

public class SceneDialog {
    private static SceneDialog sceneDialog = new SceneDialog();
    private AlertDialog alertDialog;

    public static SceneDialog getInstance() {
        return sceneDialog;
    }

    public void showDialog(Context context, String title, String content) {
        if (alertDialog == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            View alView = View.inflate(context, R.layout.use_for_scene_dialog, null);
            TextView tv_title = alView.findViewById(R.id.tv_title);
            TextView tv_content = alView.findViewById(R.id.tv_content);
            ImageView iv_quit = alView.findViewById(R.id.iv_quit);

            tv_title.setText(title);
            tv_content.setText(content);
            iv_quit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismissDialog();
                }
            });
            builder.setView(alView);
            alertDialog = builder.create();
        }
        alertDialog.show();
        resetDialog();
    }
    private void resetDialog(){
        Window window = alertDialog.getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
        layoutParams.y = 375;
        layoutParams.width=720;
        window.setAttributes(layoutParams);
    }


    public void dismissDialog() {
        if (alertDialog != null) {
            alertDialog.dismiss();
            alertDialog = null;
        }
    }
}

你可能感兴趣的:(java,android,开发语言,ide)