Advertisement
Sketchware

Gmail com caixa diálogo

Jan 17th, 2023
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. Button button = (Button) findViewById(R.id.your_button_id);
  2. button.setOnClickListener(new View.OnClickListener() {
  3.     @Override
  4.     public void onClick(View v) {
  5.         AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  6.         builder.setTitle("Insira Assunto e Mensagem");
  7.         final EditText subjectInput = new EditText(MainActivity.this);
  8.         subjectInput.setHint("Assunto");
  9.         final EditText messageInput = new EditText(MainActivity.this);
  10.         messageInput.setHint("Mensagem");
  11.         LinearLayout layout = new LinearLayout(MainActivity.this);
  12.         layout.setOrientation(LinearLayout.VERTICAL);
  13.         layout.addView(subjectInput);
  14.         layout.addView(messageInput);
  15.         builder.setView(layout);
  16.         builder.setPositiveButton("Enviar", new DialogInterface.OnClickListener() {
  17.             @Override
  18.             public void onClick(DialogInterface dialog, int which) {
  19.                 String subject = subjectInput.getText().toString();
  20.                 String message = messageInput.getText().toString();
  21.                 Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
  22.                 emailIntent.setData(Uri.parse("mailto: endereco_de_email@gmail.com"));
  23.                 emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
  24.                 emailIntent.putExtra(Intent.EXTRA_TEXT, message);
  25.                 startActivity(emailIntent);
  26.             }
  27.         });
  28.         builder.setNegativeButton("Cancelar", null);
  29.         builder.create().show();
  30.     }
  31. });
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement