如何在AlertDialog中设置正面和负面按钮的顺序? [英] How can I set the order of the positive and negative buttons in AlertDialog?

查看:110
本文介绍了如何在AlertDialog中设置正面和负面按钮的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要执行此操作完全是另一个讨论,但是我需要找出使所有警报对话框的右侧都带有肯定按钮的最佳方法.请注意,在3.0及以下版本中,按钮通常显示为确定"/取消",而在4.0及以上版本中,按钮则显示为取消/确定".我想强制我的应用程序以尽可能简单的方式使用取消/确定".我的应用程序中有很多AlertDialogs.

Why I want to do this is another discussion entirely, but I need to figure out the best way to make all my alert dialogs have the positive button on the right side. Note that in version 3.0 and below the buttons normally appear as OK / Cancel and in 4.0 and above it is Cancel / OK. I want to force my application to use Cancel / OK in the simplest way possible. I have a lot of AlertDialogs in the application.

推荐答案

不幸的是,我不相信你可以.但是,引用文档:

Unfortunately, I don't believe you can. However, to quote the documentation:

注意:您只能将每种按钮类型之一添加到AlertDialog.也就是说,您不能有多个正"按钮.这将可能的按钮数限制为三个:正数,中性和负数.这些名称在技术上与按钮的实际功能无关,但是应该可以帮助您跟踪哪个按钮在做什么.

Note: You can only add one of each button type to the AlertDialog. That is, you cannot have more than one "positive" button. This limits the number of possible buttons to three: positive, neutral, and negative. These names are technically irrelevant to the actual functionality of your buttons, but should help you keep track of which one does what.

因此您可以将不同的按钮转换为所需的任何按钮.您在这里看到的是已切换的顺序(从答案进行排序):

So you can turn the different buttons into whatever you want. What you're seeing here is the order having switched (ordering from this answer):

  • 在ICS之前的设备上,按钮顺序(从左到右)为正-中-负".
  • 在使用ICS的较新设备上,按钮顺序(从左到右)现在为负-中性-正.

您可以尝试检查 Build.VERSION 并使用它来确定运行时哪个按钮.

You might try checking the Build.VERSION and using that to decide which button is which at runtime.

这篇关于如何在AlertDialog中设置正面和负面按钮的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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