android.app.AlertDialog类的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(190)

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

AlertDialog介绍

暂无

代码示例

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

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
// ...Irrelevant code for customizing the buttons and title
LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.alert_label_editor, null);
dialogBuilder.setView(dialogView);

EditText editText = (EditText) dialogView.findViewById(R.id.label_field);
editText.setText("test label");
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();

代码示例来源:origin: k9mail/k-9

@Override
public boolean retain() {
  if (mDialog != null) {
    // Retain entered passwords and checkbox state
    if (mIncomingPasswordView != null) {
      mIncomingPassword = mIncomingPasswordView.getText().toString();
    }
    if (mOutgoingPasswordView != null) {
      mOutgoingPassword = mOutgoingPasswordView.getText().toString();
      mUseIncoming = mUseIncomingView.isChecked();
    }
    // Dismiss dialog
    mDialog.dismiss();
    // Clear all references to UI objects
    mDialog = null;
    mIncomingPasswordView = null;
    mOutgoingPasswordView = null;
    mUseIncomingView = null;
    return true;
  }
  return false;
}

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

Button more = (Button) findViewById(R.id.more);
more.setOnClickListener(new View.OnClickListener() {
  public void onClick(View view) {
    //Intent myIntent = new Intent(view.getContext(), agones.class);
    //startActivityForResult(myIntent, 0);

    AlertDialog alertDialog = new AlertDialog.Builder(<YourActivityName>this).create(); //Read Update
    alertDialog.setTitle("hi");
    alertDialog.setMessage("this is my app");

    alertDialog.setButton("Continue..", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
       // here you can add functions
      }
    });

    alertDialog.show();  //<-- See This!
  }

});

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

// Linkify the message
 final SpannableString s = new SpannableString(msg);
 Linkify.addLinks(s, Linkify.ALL);
 final AlertDialog d = new AlertDialog.Builder(activity)
   .setPositiveButton(android.R.string.ok, null)
   .setIcon(R.drawable.icon)
   .setMessage( s )
   .create();
 d.show();
 // Make the textview clickable. Must be called after show()
 ((TextView)d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());

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

AlertDialog.Builder b = new AlertDialog.Builder(this);//....
AlertDialog dialog = b.create();

dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

dialog.show();

代码示例来源:origin: android-hacker/VirtualXposed

@Override
protected void onDestroy() {
  if (dialog != null && dialog.isShowing()) {
    dialog.dismiss();
  }
  super.onDestroy();
}

代码示例来源:origin: google/agera

@Nullable
@Override
public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container,
  @Nullable final Bundle savedInstanceState) {
 final View view = inflater.inflate(R.layout.notes_fragment, container, false);
 // Find the clear button and wire the click listener to call the clear notes updatable
 view.findViewById(R.id.clear).setOnClickListener(v -> notesStore.clearNotes());
 // Find the add button and wire the click listener to show a dialog that in turn calls the add
 // note from text from the notes store when adding notes
 view.findViewById(R.id.add).setOnClickListener(v -> {
  final EditText editText = new EditText(v.getContext());
  editText.setId(R.id.edit);
  new AlertDialog.Builder(v.getContext())
    .setTitle(R.string.add_note)
    .setView(editText)
    .setPositiveButton(R.string.add, (d, i) -> {
     notesStore.insertNoteFromText(editText.getText().toString());
    })
    .create().show();
 });
 // Setup the recycler view using the repository adapter
 recyclerView = (RecyclerView) view.findViewById(R.id.result);
 recyclerView.setAdapter(adapter);
 recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
 final ImageView imageView = (ImageView) view.findViewById(R.id.background);
 updatable = () -> backgroundRepository.get().ifSucceededSendTo(imageView::setImageBitmap);
 return view;
}

代码示例来源:origin: mthli/Knife

private void showLinkDialog() {
  final int start = knife.getSelectionStart();
  final int end = knife.getSelectionEnd();
  AlertDialog.Builder builder = new AlertDialog.Builder(this);
  builder.setCancelable(false);
  View view = getLayoutInflater().inflate(R.layout.dialog_link, null, false);
  final EditText editText = (EditText) view.findViewById(R.id.edit);
  builder.setView(view);
  builder.setTitle(R.string.dialog_title);
  builder.setPositiveButton(R.string.dialog_button_ok, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
      String link = editText.getText().toString().trim();
      if (TextUtils.isEmpty(link)) {
        return;
      }
      // When KnifeText lose focus, use this method
      knife.link(link, start, end);
    }
  });
  builder.setNegativeButton(R.string.dialog_button_cancel, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
      // DO NOTHING HERE
    }
  });
  builder.create().show();
}

代码示例来源:origin: k9mail/k-9

View layout = mDialog.getLayoutInflater().inflate(R.layout.accounts_password_prompt, scrollView);
TextView intro = layout.findViewById(R.id.password_prompt_intro);
String serverPasswords = activity.getResources().getQuantityString(
    R.plurals.settings_import_server_passwords,
  TextView incomingText = layout.findViewById(R.id.password_prompt_incoming_server);
  incomingText.setText(activity.getString(R.string.settings_import_incoming_server,
                      incoming.host));
  mIncomingPasswordView = layout.findViewById(R.id.incoming_server_password);
  mIncomingPasswordView.addTextChangedListener(this);
} else {
  layout.findViewById(R.id.incoming_server_prompt).setVisibility(View.GONE);
  mOutgoingPasswordView = layout.findViewById(R.id.outgoing_server_password);
  mOutgoingPasswordView.addTextChangedListener(this);
  mUseIncomingView = layout.findViewById(R.id.use_incoming_server_password);
    mUseIncomingView.setChecked(false);
    mUseIncomingView.setVisibility(View.GONE);
    mOutgoingPasswordView.setEnabled(true);
mDialog.show();

代码示例来源:origin: cymcsg/UltimateAndroid

private void showDownloadDialog() {
  builder = new AlertDialog.Builder(mContext);
  final LayoutInflater inflater = LayoutInflater.from(mContext);
  View v = inflater.inflate(R.layout.progress_update, null);
  mProgress = (ProgressBar) v.findViewById(R.id.progress);
  updatePercentTextView = (TextView) v.findViewById(R.id.updatePercentTextView);
  updateCurrentTextView = (TextView) v.findViewById(R.id.updateCurrentTextView);
  updateCurrentTextView.setText(prepareDownloadingTextViewString);
  updateTotalTextView = (TextView) v.findViewById(R.id.updateTotalTextView);
  // builder.setCustomTitle(inflater.inflate(R.layout.progress_update_title, null));
  builder.setTitle(downloadTitle);
  builder.setView(v);
  builder.setNegativeButton(downloadCancel, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
      dialog.dismiss();
      interceptFlag = true;
    }
  });
  progressDialog = builder.create();
  progressDialog.show();
}

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

Intent intent = new Intent( "com.android.camera.action.CROP" );
intent.setType( "image/*" );
intent.setData( _captureUri );
intent.putExtra( "outputX", 128 );
intent.putExtra( "outputY", 128 );
AlertDialog.Builder builder = new AlertDialog.Builder( this );
builder.setTitle( R.string.choose_crop_title );
builder.setAdapter( adapter, new DialogInterface.OnClickListener() {
  public void onClick( DialogInterface dialog, int item )
builder.setOnCancelListener( new DialogInterface.OnCancelListener() {
  @Override
  public void onCancel( DialogInterface dialog )
AlertDialog alert = builder.create();
alert.show();

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

AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

String names[] ={"A","B","C","D"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext,android.R.layout.simple_list_item_1,names);

LayoutInflater inflater = getLayoutInflater();
View convertView = (View)inflater.inflate(R.layout.list_layout, null);
ListView lv = (ListView) convertView.findViewById(R.id.listView1);
lv.setAdapter(adapter);
alertDialog.setView(convertView);
alertDialog.setTitle("List");
final AlertDialog ad = alertDialog.show();

lv.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id)
  {
    //Toast.makeText(mContext, position, Toast.LENGTH_LONG).show();
    ad.dismiss();
  }
});

代码示例来源:origin: scola/Qart

editTextView.setVisibility(View.VISIBLE);
  if (qrText != null && qrText.isEmpty() == false) {
    mEditTextView.setText(qrText);
    mEditTextView.setSelection(qrText.length());
new AlertDialog.Builder(this)
  .setTitle(_(R.string.color_or_black))
  .setMessage(_(R.string.colorful_msg))
  .setPositiveButton(R.string.colorful, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialogInterface, int i) {
  .create()
  .show();
  Intent shareIntent = new Intent();
  shareIntent.setAction(Intent.ACTION_SEND);
  shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  shareIntent.setType("image/png");
  shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);

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

View promptView = layoutInflater.inflate(R.layout.prompt, null);
final AlertDialog alertD = new AlertDialog.Builder(this).create();
EditText userInput = (EditText) promptView.findViewById(R.id.userInput);
Button btnAdd1 = (Button) promptView.findViewById(R.id.btnAdd1);
Button btnAdd2 = (Button) promptView.findViewById(R.id.btnAdd2);
alertD.setView(promptView);
alertD.show();

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

// Get our tools
AlertDialog dialog;
AlertDialog.Builder builder;
// The EditText to show your Text
LayoutInflater inflater = 
  (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.dialog,
    (ViewGroup) this.findViewById(R.id.showText));
EditText showText = (EditText) layout.findViewById(R.id.showText);
showText.setText("Some selectable text goes here.");
// Build the Dialog
builder = new AlertDialog.Builder(this);
builder.setView(layout);
dialog = builder.create();
// Some eye-candy
dialog.setTitle("Selectable text");
dialog.setCancelable(true);
dialog.show();

代码示例来源:origin: syncthing/syncthing-android

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
    case R.id.create_folder:
      final EditText et = new EditText(this);
      AlertDialog dialog = new AlertDialog.Builder(this)
          .setTitle(R.string.create_folder)
          .setView(et)
          .setPositiveButton(android.R.string.ok,
              (dialogInterface, i) -> createFolder(et.getText().toString())
          )
          .setNegativeButton(android.R.string.cancel, null)
          .create();
      dialog.setOnShowListener(dialogInterface -> ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
          .showSoftInput(et, InputMethodManager.SHOW_IMPLICIT));
      dialog.show();
      return true;
    case R.id.select:
      Intent intent = new Intent()
          .putExtra(EXTRA_RESULT_DIRECTORY, Util.formatPath(mLocation.getAbsolutePath()));
      setResult(Activity.RESULT_OK, intent);
      finish();
      return true;
    case android.R.id.home:
      finish();
      return true;
    default:
      return super.onOptionsItemSelected(item);
  }
}

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

LayoutInflater li = LayoutInflater.from(context);
       View promptsView = li.inflate(R.layout.my_dialog_layout, null);
       AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
       alertDialogBuilder.setView(promptsView);
       // set dialog message
       alertDialogBuilder.setTitle("My Dialog..");
       alertDialogBuilder.setIcon(R.drawable.ic_launcher);
       // create alert dialog
       final AlertDialog alertDialog = alertDialogBuilder.create();
       final Spinner mSpinner= (Spinner) promptsView
           .findViewById(R.id.mySpinner);
       final Button mButton = (Button) promptsView
           .findViewById(R.id.myButton);
       // reference UI elements from my_dialog_layout in similar fashion
       mSpinner.setOnItemSelectedListener(new OnSpinnerItemClicked());
       // show it
       alertDialog.show();
       alertDialog.setCanceledOnTouchOutside(false);

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

AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setTitle("Choose your Application Theme");
b.setSingleChoiceItems(choose, 0, null);
b.setPositiveButton("OK",this);
d.show();
int position = alert.getListView().getCheckedItemPosition();
Intent intent = new Intent(this, EditTextSmartPhoneActivity.class);
intent.putExtra("position", position);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

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

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    android.R.layout.select_dialog_item, items);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
        new AlertDialog.Builder(MainActivity.this)
            .setMessage(
                "External Storeage (SD Card) is required.\n\nCurrent state: "
      Intent intent = new Intent();
  mImageCaptureUri = data.getData();
  Log.i("TAG",
      "After Crop mImageCaptureUri " + mImageCaptureUri.getPath());
  Bundle extras = data.getExtras();
        getApplicationContext(), cropOptions);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Choose Crop App");
    builder.setAdapter(adapter,
    alert.show();

代码示例来源:origin: termux/termux-app

LinkedHashSet<CharSequence> urlSet = extractUrls(text);
if (urlSet.isEmpty()) {
  new AlertDialog.Builder(this).setMessage(R.string.select_url_no_found).show();
  return;
dialog.setOnShowListener(di -> {
  ListView lv = dialog.getListView(); // this is a ListView with your "buds" in it
  lv.setOnItemLongClickListener((parent, view, position, id) -> {
    dialog.dismiss();
    String url = (String) urls[position];
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    try {
      startActivity(i, null);
    } catch (ActivityNotFoundException e) {
      startActivity(Intent.createChooser(i, null));
});
dialog.show();

相关文章