Android:正、负和中性按钮之间的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11401951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:17:02  来源:igfitidea点击:

Android: Difference between positive, negative, and neutral button

androidbuttonandroid-alertdialog

提问by bibismcbryde

Is there a functional difference between positive, negative, and neutral buttons, particularly in the context of AlertDialogs?

肯定按钮、否定按钮和中性按钮之间是否存在功能差异,尤其是在 AlertDialogs 的上下文中?

回答by Devunwired

Just the position they take within the dialog...

只是他们在对话中的位置......

  • On devices prior to Honeycomb, the button order (left to right) was POSITIVE - NEUTRAL - NEGATIVE.
  • On newer devices using the Holo theme, the button order (left to right) is now NEGATIVE - NEUTRAL - POSITIVE.
  • 在 Honeycomb 之前的设备上,按钮顺序(从左到右)是正 - 中性 - 负。
  • 在使用 Holo 主题的较新设备上,按钮顺序(从左到右)现在是负 - 中性 - 正。

回答by ayz4sci

On Lolipop and above or whenever you use Theme.AppCompat.Lightstyle, the buttons are arranged from left to right: Neutral, Negative and Positive.

在 Lolipop 及更高版本或任何时候使用Theme.AppCompat.Lightstyle,按钮从左到右排列:Neutral、Negative 和 Positive。

Note: the Neutral button is always placed at the extreme left while the Negative and Positive buttons are packed together towards the right. [Took me awhile battling with this.]

注意:Neutral 按钮总是放在最左边,而 Negative 和 Positive 按钮放在一起向右。[我花了一些时间来解决这个问题。]

Material Design Dialog Button Placements

Material Design 对话框按钮位置

回答by thegrinner

To quote the documentation:

引用文档

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.

注意:您只能将每种按钮类型中的一种添加到 AlertDialog。也就是说,您不能有多个“肯定”按钮。这将可能的按钮数量限制为三个:正面、中性和负面。这些名称在技术上与按钮的实际功能无关,但可以帮助您跟踪哪个按钮的作用。

So it's entirely down to how you want to use it. It also influences order in a left-to-right sense (see Devunwired's answer for the ordering).

所以这完全取决于你想如何使用它。它还影响从左到右的顺序(请参阅 Devunwired 的排序答案)。

回答by aaa bbb

As stated earlier, it defines the order, and you can have only one button of each kind. However the order I get (left to right) is Neutral, Negative, Positive both on a phone running Marshmallow and Android Studio emulator configured to Jelly Bean. I use AppCompat libs, so the behavior I observe may be typical for newer Android versions. Anyway it is not Negative, Neutral, Positive (i.e. not as it was stated earlier).

如前所述,它定义了顺序,并且每种类型只能有一个按钮。但是,在运行 Marshmallow 和配置为 Jelly Bean 的 Android Studio 模拟器的手机上,我得到的顺序(从左到右)是中性、负、正。我使用 AppCompat 库,因此我观察到的行为可能是较新的 Android 版本的典型行为。无论如何,它不是负面的、中性的、正面的(即不像之前所说的那样)。

回答by Herrbert74

According to Material Design Style Guide you shouldn't use neutral buttons anymore:

根据 Material Design Style Guide,您不应再使用中性按钮:

Dialog specs

对话框规格