android.app.Dialog.setContentView()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(12.8k)|赞(0)|评价(0)|浏览(327)

本文整理了Java中android.app.Dialog.setContentView()方法的一些代码示例,展示了Dialog.setContentView()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dialog.setContentView()方法的具体详情如下:
包路径:android.app.Dialog
类名称:Dialog
方法名:setContentView

Dialog.setContentView介绍

暂无

代码示例

代码示例来源:origin: lipangit/JiaoZiVideoPlayer

public Dialog createDialogWithView(View localView) {
  Dialog dialog = new Dialog(getContext(), R.style.jz_style_dialog_progress);
  dialog.setContentView(localView);
  Window window = dialog.getWindow();
  window.addFlags(Window.FEATURE_ACTION_BAR);
  window.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
  window.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
  window.setLayout(-2, -2);
  WindowManager.LayoutParams localLayoutParams = window.getAttributes();
  localLayoutParams.gravity = Gravity.CENTER;
  window.setAttributes(localLayoutParams);
  return dialog;
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

public static Dialog showDialogForLoading(Activity context) {
  View view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null);
  TextView loadingText = (TextView)view.findViewById(R.id.id_tv_loading_dialog_text);
  loadingText.setText("加载中...");
  mLoadingDialog = new Dialog(context, R.style.CustomProgressDialog);
  mLoadingDialog.setCancelable(true);
  mLoadingDialog.setCanceledOnTouchOutside(false);
  mLoadingDialog.setContentView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
  mLoadingDialog.show();
  return  mLoadingDialog;
}

代码示例来源:origin: stackoverflow.com

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {

  // the content
  final RelativeLayout root = new RelativeLayout(getActivity());
  root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

  // creating the fullscreen dialog
  final Dialog dialog = new Dialog(getActivity());
  dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  dialog.setContentView(root);
  dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.YELLOW));
  dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

  return dialog;
}

代码示例来源:origin: ZieIony/Carbon

private void initLayout() {
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  Window window = getWindow();
  if (window != null) {
    window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    window.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
  }
  dialogLayout = getLayoutInflater().inflate(R.layout.carbon_dialog, null);
  container = dialogLayout.findViewById(R.id.carbon_windowContent);
  super.setContentView(dialogLayout);
}

代码示例来源:origin: libgdx/libgdx

Dialog createDialog () {
  textView = createView(context);
  textView.setOnKeyListener(this);
  FrameLayout.LayoutParams textBoxLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
    FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
  textView.setLayoutParams(textBoxLayoutParams);
  textView.setFocusable(true);
  textView.setFocusableInTouchMode(true);
  textView.setImeOptions(textView.getImeOptions() | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
  final FrameLayout layout = new FrameLayout(context);
  ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
  layout.setLayoutParams(layoutParams);
  layout.addView(textView);
  layout.setOnTouchListener(this);
  dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
  dialog.setContentView(layout);
  return dialog;
}

代码示例来源:origin: libgdx/libgdx

Dialog createDialog () {
  textView = createView(context);
  textView.setOnKeyListener(this);
  FrameLayout.LayoutParams textBoxLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
    FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
  textView.setLayoutParams(textBoxLayoutParams);
  textView.setFocusable(true);
  textView.setFocusableInTouchMode(true);
  textView.setImeOptions(textView.getImeOptions() | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
  final FrameLayout layout = new FrameLayout(context);
  ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
  layout.setLayoutParams(layoutParams);
  layout.addView(textView);
  layout.setOnTouchListener(this);
  dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
  dialog.setContentView(layout);
  return dialog;
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
 * 显示加载对话框
 * @param context 上下文
 * @param msg 对话框显示内容
 * @param cancelable 对话框是否可以取消
 */
public static Dialog showDialogForLoading(Activity context, String msg, boolean cancelable) {
  View view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null);
  TextView loadingText = (TextView)view.findViewById(R.id.id_tv_loading_dialog_text);
  loadingText.setText(msg);
  mLoadingDialog = new Dialog(context, R.style.CustomProgressDialog);
  mLoadingDialog.setCancelable(cancelable);
  mLoadingDialog.setCanceledOnTouchOutside(false);
  mLoadingDialog.setContentView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
  mLoadingDialog.show();
  return  mLoadingDialog;
}

代码示例来源:origin: facebook/facebook-android-sdk

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
  dialog = new Dialog(getActivity(), R.style.com_facebook_auth_dialog);
  View view = initializeContentView(DeviceRequestsHelper.isAvailable() && !this.isRetry);
  dialog.setContentView(view);
  return dialog;
}

代码示例来源:origin: facebook/stetho

@Override
 public void onClick(View v) {
  int id = v.getId();
  if (id == R.id.settings_btn) {
   SettingsActivity.show(MainActivity.this);
  } else if (id == R.id.apod_btn) {
   APODActivity.show(MainActivity.this);
  } else if (id == R.id.irc_btn) {
   IRCConnectActivity.show(MainActivity.this);
  } else if (id == R.id.about) {
   View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog_layout, null);
   Dialog dialog = new Dialog(MainActivity.this);
   dialog.setContentView(view);
   dialog.setTitle(getString(R.string.app_name));
   dialog.show();
  }
 }
};

代码示例来源:origin: jaydenxiao2016/AndroidFire

public MDSelectionDialog(Builder builder) {
  this.mBuilder = builder;
  mDialog = new Dialog(mContext, R.style.MyDialogStyle);
  dialogView = View.inflate(mContext, R.layout.widget_md_mid_dialog, null);
  linearLayout = (LinearLayout) dialogView.findViewById(R.id.md_mid_dialog_linear);
  mDialog.setContentView(dialogView); // 一定要在setAttributes(lp)之前才有效
  //设置dialog的宽
  Window dialogWindow = mDialog.getWindow();
  WindowManager.LayoutParams lp = dialogWindow.getAttributes();
  lp.width = (int) (ScreenSizeUtils.getInstance(mContext).getScreenWidth() * builder.itemWidth);
  lp.gravity = Gravity.CENTER;
  lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
  dialogWindow.setAttributes(lp);
  mDialog.setCanceledOnTouchOutside(builder.isTouchOutside());
}

代码示例来源:origin: facebook/facebook-android-sdk

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
  dialog = new Dialog(getActivity(), R.style.com_facebook_auth_dialog);
  LayoutInflater inflater = getActivity().getLayoutInflater();
  View view = inflater.inflate(R.layout.com_facebook_device_auth_dialog_fragment, null);
  progressBar = (ProgressBar)view.findViewById(R.id.progress_bar);
  confirmationCode = (TextView)view.findViewById(R.id.confirmation_code);
  Button cancelButton = (Button) view.findViewById(R.id.cancel_button);
  cancelButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      dialog.dismiss();
    }
  });
  TextView instructions = (TextView)view.findViewById(
      R.id.com_facebook_device_auth_instructions);
  instructions.setText(
      Html.fromHtml(getString(R.string.com_facebook_device_auth_instructions)));
  dialog.setContentView(view);
  this.startShare();
  return dialog;
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

mBrightnessDialog.setContentView(localView);
mBrightnessDialog.getWindow().addFlags(8);
mBrightnessDialog.getWindow().addFlags(32);

代码示例来源:origin: Bigkoo/Android-PickerView

public void createDialog() {
  if (dialogView != null) {
    mDialog = new Dialog(context, R.style.custom_dialog2);
    mDialog.setCancelable(mPickerOptions.cancelable);//不能点外面取消,也不能点back取消
    mDialog.setContentView(dialogView);
    Window dialogWindow = mDialog.getWindow();
    if (dialogWindow != null) {
      dialogWindow.setWindowAnimations(R.style.picker_view_scale_anim);
      dialogWindow.setGravity(Gravity.CENTER);//可以改成Bottom
    }
    mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
      @Override
      public void onDismiss(DialogInterface dialog) {
        if (onDismissListener != null) {
          onDismissListener.onDismiss(BasePickerView.this);
        }
      }
    });
  }
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

mVolumeDialog.setContentView(localView);
mVolumeDialog.getWindow().addFlags(8);
mVolumeDialog.getWindow().addFlags(32);

代码示例来源:origin: MindorksOpenSource/android-mvp-architecture

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
  // the content
  final RelativeLayout root = new RelativeLayout(getActivity());
  root.setLayoutParams(new ViewGroup.LayoutParams(
      ViewGroup.LayoutParams.MATCH_PARENT,
      ViewGroup.LayoutParams.WRAP_CONTENT));
  // creating the fullscreen dialog
  final Dialog dialog = new Dialog(getContext());
  dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  dialog.setContentView(root);
  if (dialog.getWindow() != null) {
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dialog.getWindow().setLayout(
        ViewGroup.LayoutParams.MATCH_PARENT,
        ViewGroup.LayoutParams.WRAP_CONTENT);
  }
  dialog.setCanceledOnTouchOutside(false);
  return dialog;
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

public NormalAlertDialog(Builder builder) {
  this.mBuilder = builder;
  mDialog = new Dialog(mContext, R.style.NormalDialogStyle);
  mDialogView = View.inflate(mContext, R.layout.widget_dialog_normal, null);
  mTitle = (TextView) mDialogView.findViewById(R.id.dialog_normal_title);
  mContent = (TextView) mDialogView.findViewById(R.id.dialog_normal_content);
  mLeftBtn = (Button) mDialogView.findViewById(R.id.dialog_normal_leftbtn);
  mRightBtn = (Button) mDialogView.findViewById(R.id.dialog_normal_rightbtn);
  mSingleBtn = (Button) mDialogView.findViewById(R.id.dialog_normal_midbtn);
  mLine = (TextView) mDialogView.findViewById(R.id.dialog_normal_line);
  mDialogView.setMinimumHeight((int) (ScreenSizeUtils.getInstance(mContext).getScreenHeight
      () * builder.getHeight()));
  mDialog.setContentView(mDialogView);
  Window dialogWindow = mDialog.getWindow();
  WindowManager.LayoutParams lp = dialogWindow.getAttributes();
  lp.width = (int) (ScreenSizeUtils.getInstance(mContext).getScreenWidth() * builder.getWidth());
  lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
  lp.gravity = Gravity.CENTER;
  dialogWindow.setAttributes(lp);
  initDialog(builder);
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

public MDAlertDialog(Builder builder) {
  mBuilder = builder;
  mDialog = new Dialog(mContext, R.style.MyDialogStyle);
  mDialogView = View.inflate(mContext, R.layout.widget_md_dialog, null);
  mTitle = (TextView) mDialogView.findViewById(R.id.md_dialog_title);
  mContent = (TextView) mDialogView.findViewById(R.id.md_dialog_content);
  mLeftBtn = (TextView) mDialogView.findViewById(R.id.md_dialog_leftbtn);
  mRightBtn = (TextView) mDialogView.findViewById(R.id.md_dialog_rightbtn);
  mDialogView.setMinimumHeight((int) (ScreenSizeUtils.getInstance(mContext).getScreenHeight
      () * builder.getHeight()));
  mDialog.setContentView(mDialogView);
  Window dialogWindow = mDialog.getWindow();
  WindowManager.LayoutParams lp = dialogWindow.getAttributes();
  lp.width = (int) (ScreenSizeUtils.getInstance(mContext).getScreenWidth() * builder.getWidth());
  lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
  lp.gravity = Gravity.CENTER;
  dialogWindow.setAttributes(lp);
  initDialog();
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

public MDEditDialog(Builder builder) {
  mBuilder = builder;
  mDialog = new Dialog(mContext, R.style.MyDialogStyle);
  mDialogView = View.inflate(mContext, R.layout.widget_edit_dialog, null);
  mTitle = (TextView) mDialogView.findViewById(R.id.edit_dialog_title);
  mEdit = (EditText) mDialogView.findViewById(R.id.edit_dialog_exittext);
  mLeftBtn = (TextView) mDialogView.findViewById(R.id.edit_dialog_leftbtn);
  mRightBtn = (TextView) mDialogView.findViewById(R.id.edit_dialog_rightbtn);
  lineView = (View) mDialogView.findViewById(R.id.edit_dialog_line);
  mDialogView.setMinimumHeight((int) (ScreenSizeUtils.getInstance(mContext).getScreenHeight
      () * builder.getMinHeight()));
  mDialog.setContentView(mDialogView);
  Window dialogWindow = mDialog.getWindow();
  WindowManager.LayoutParams lp = dialogWindow.getAttributes();
  lp.width = (int) (ScreenSizeUtils.getInstance(mContext).getScreenWidth() * builder
      .getWidth());
  lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
  lp.gravity = Gravity.CENTER;
  dialogWindow.setAttributes(lp);
  initDialog();
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldFindViewsWithinAContentViewThatWasPreviouslySet() throws Exception {
 Dialog dialog = new Dialog(context);
 dialog.setContentView(dialog.getLayoutInflater().inflate(R.layout.main, null));
 assertThat(dialog.<TextView>findViewById(R.id.title)).isInstanceOf((Class<? extends TextView>) TextView.class);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void setContentViewWithViewAllowsFindById() throws Exception {
 final int viewId = 1234;
 final Dialog dialog = new Dialog(context);
 final View view = new View(context);
 view.setId(viewId);
 dialog.setContentView(view);
 assertSame(view, dialog.findViewById(viewId));
}

相关文章