当前位置: 首页 > 面试题库 >

Android警报对话框并设置肯定按钮

梁丘琛
2023-03-14
问题内容

这是一个滑块难题。拼图完成后,我想显示一个带有“确定”按钮的对话框。当按下“确定”按钮时,我使用Intent来通过Android浏览器加载网站。唯一的问题是,使用当前代码,当拼图完成后,它不会加载一个框(当我使用时会加载null)。它什么也没做。有任何想法吗?

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(!puzzle.isSolved() ? R.string.title_stats : stats.isNewBest() ? R.string.title_new_record : R.string.title_solved);
builder.setMessage(msg);
builder.setPositiveButton(R.string.label_ok, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("http://www..com"));
        Bundle b = new Bundle();
        b.putBoolean("new_window", true); //sets new window
        intent.putExtras(b);
        startActivity(intent);
     }
});

问题答案:
AlertDialog.Builder builder = new AlertDialog.Builder(your_activity.this);
builder.setTitle(!puzzle.isSolved() ? R.string.title_stats : stats.isNewBest() ? R.string.title_new_record : R.string.title_solved);
builder.setMessage(msg);
builder.setPositiveButton(R.string.label_ok, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("http://www..com"));
        Bundle b = new Bundle();
        b.putBoolean("new_window", true); //sets new window
        intent.putExtras(b);
        startActivity(intent);
     }
});
builder.show();

试试这个



 类似资料:
  • 我已经创建了一个警报对话框构建器,其中正在显示一个表单的对话,我的积极按钮名称是提交,我希望按钮被禁用,除非表单中的所有字段都被填满。下面是我的代码,任何人可以帮助我在这方面的工作。谢谢

  • 我有一个简单的警报对话框与单选项目 我已经在我的主题中添加了自定义样式的警报对话框 这是我的风格 当我运行应用程序时,我会看到此警报 有没有办法在不创建自定义布局的情况下更改单选按钮附近文本的颜色?

  • 最近我从支持库切换到com.google.android.Material:Material:1.0.0 但是现在我遇到了一个问题,在这个页面中有一个注释https://github.com/Material-Components/Material-Components-android/blob/master/docs/geting-started.md 注意:使用Material Compone

  • 我试图改变"取消"按钮上的Android L警报对话框的颜色设置alertDialogTheme属性的我的主题如下: 现在AlertDialogStyle为空: 我知道我可以用 属性更新这些按钮的颜色/样式。我的问题是,从主题下降。材料。光。对话框风格,我所有的对话框都将其宽度减小到(看起来)wrap_content。我有几个自定义警报对话框,宽度看起来很糟糕。有没有人遇到这个问题,如果有,有人解

  • 我有一个按钮(CustomDilaog活动),当点击显示自定义对话框和密码编辑文本,确定按钮和取消按钮时,如果你输入正确的密码,它会打开另一个活动(文本活动),直到现在一切正常, 我有两个部分的问题。 第一部分:当我在(文本活动)并按后退按钮返回(CustomDilaog活动)时,仍然对话框显示在它上面,如何让它关闭 第二部分:对话框启动后,如果我不写密码,只需单击“确定”按钮,edittext为

  • 我正在开发一个Android应用程序。我需要自定义警报对话框按钮,因为它以未指定的方式向我显示按钮。 调用警报对话框的代码为: 在