final EditText et = new EditText(this); new AlertDialog.Builder(this).setTitle("搜索") .setIcon(android.R.drawable.ic_dialog_info) .setView(et) .setPositiveButton("确定", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { String input = et.getText().toString(); if (input.equals("")) { Toast.makeText(getApplicationContext(), "搜索内容不能为空!" + input, Toast.LENGTH_LONG).show(); } else { Intent intent = new Intent(); intent.putExtra("content", input); intent.setClass(MainActivity.this, SearchActivity.class); startActivity(intent); } } }) .setNegativeButton("取消", null) .show();