gpt4 book ai didi

java - 从警报对话框按钮打开链接 Android

转载 作者:行者123 更新时间:2023-11-30 08:13:19 24 4
gpt4 key购买 nike

我有一个弹出的警告框,要求用户帮助翻译两个按钮“帮助翻译”和“关闭”我如何做到这一点,当用户点击“帮助翻译”时,它会将他们带到网站 example.com .

这可以用警告对话框来完成还是我必须用自定义框制作一个布局文件

还有如何让“帮助翻译”按钮向左,“关闭”按钮向右

enter image description here

@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;

最佳答案

PositiveButtonNegativeButton 实现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

关于java - 从警报对话框按钮打开链接 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30024635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com