从警报对话框按钮 Android 打开 Link
Open Link From Alert Dialog Box Button Android
我有一个弹出的警告框,要求用户帮助翻译两个按钮 "Help Translate" 和 "Close" 我如何做到这一点,所以当用户单击 "Help Translate" 时,它需要它们到网站 example.com。
这可以用警告对话框完成吗,还是我必须用自定义框制作布局文件
以及如何让 "Help Translate" 按钮向左,"Close" 向右
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()) {
//noinspection SimplifiableIfStatement
case R.id.action_about:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle(getResources().getString(R.string.app_name));
builder.setMessage(getResources().getString(R.string.about_text));
builder.setNeutralButton("Close", null);
builder.setCancelable(true);
AlertDialog alert = builder.create();
alert.show();
return true;
case R.id.action_translate:
builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle(getResources().getString(R.string.app_name));
builder.setMessage(getResources().getString(R.string.translate_text));
builder.setPositiveButton ("Help Translate", null);
builder.setNeutralButton("Close", null);
builder.setCancelable(true);
alert = builder.create();
alert.show();
return true;
为 PositiveButton
和 NegativeButton
实施 onClickListner()
,例如
builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// what ever you want to do with No option.
builder.dismiss();
}
});
和
builder.setPositiveButton("Help Translate", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
builder.dismiss();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
startActivity(browserIntent);
}
});
更多信息Go to
您可以使用 getButton(BUTTON_POSITIVE);
获取按钮
http://developer.android.com/reference/android/app/AlertDialog.html#getButton(int)
然后您可以在单击“帮助翻译”按钮时执行类似的操作:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
我有一个弹出的警告框,要求用户帮助翻译两个按钮 "Help Translate" 和 "Close" 我如何做到这一点,所以当用户单击 "Help Translate" 时,它需要它们到网站 example.com。
这可以用警告对话框完成吗,还是我必须用自定义框制作布局文件
以及如何让 "Help Translate" 按钮向左,"Close" 向右
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()) {
//noinspection SimplifiableIfStatement
case R.id.action_about:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle(getResources().getString(R.string.app_name));
builder.setMessage(getResources().getString(R.string.about_text));
builder.setNeutralButton("Close", null);
builder.setCancelable(true);
AlertDialog alert = builder.create();
alert.show();
return true;
case R.id.action_translate:
builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle(getResources().getString(R.string.app_name));
builder.setMessage(getResources().getString(R.string.translate_text));
builder.setPositiveButton ("Help Translate", null);
builder.setNeutralButton("Close", null);
builder.setCancelable(true);
alert = builder.create();
alert.show();
return true;
为 PositiveButton
和 NegativeButton
实施 onClickListner()
,例如
builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// what ever you want to do with No option.
builder.dismiss();
}
});
和
builder.setPositiveButton("Help Translate", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
builder.dismiss();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
startActivity(browserIntent);
}
});
更多信息Go to
您可以使用 getButton(BUTTON_POSITIVE);
获取按钮http://developer.android.com/reference/android/app/AlertDialog.html#getButton(int)
然后您可以在单击“帮助翻译”按钮时执行类似的操作:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);