我如何添加第三个按钮,一个Android警告对话框? [英] How can I add a third button to an Android Alert Dialog?

查看:124
本文介绍了我如何添加第三个按钮,一个Android警告对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该API说,警报对话框可以有一个,两个或三个按钮,但在SDK只允许一个正和负按钮。我怎么能添加第三个按钮?

The API says that the Alert Dialog can have one, two or three buttons, but the SDK only allows for a positive and negative button. How then can I add a third button?

推荐答案

这code段应有助于解释这三个不同的按钮,你可以使用:

This code snippet should help explain the three different buttons you can use:

    alertDialog = new AlertDialog.Builder(this).create();

    alertDialog.setTitle("Dialog Button");

    alertDialog.setMessage("This is a three-button dialog!");

    alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Button 1 Text", new DialogInterface.OnClickListener() {

      public void onClick(DialogInterface dialog, int id) {

        //...

    } }); 

    alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Button 2 Text", new DialogInterface.OnClickListener() {

      public void onClick(DialogInterface dialog, int id) {

        //...

    }}); 

    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Button 3 Text", new DialogInterface.OnClickListener() {

      public void onClick(DialogInterface dialog, int id) {

        //...

    }});

这篇关于我如何添加第三个按钮,一个Android警告对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆