Android: Difference between positive, negative, and neutral button

后端 未结 5 1055
日久生厌
日久生厌 2020-12-25 11:05

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

相关标签:
5条回答
  • 2020-12-25 11:39

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

    Dialog specs

    0 讨论(0)
  • 2020-12-25 11:40

    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.

    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).

    0 讨论(0)
  • 2020-12-25 11:41

    On Lolipop and above or whenever you use Theme.AppCompat.Light style, the buttons are arranged from left to right: Neutral, Negative and 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.]

    Material Design Dialog Button Placements

    0 讨论(0)
  • 2020-12-25 11:48

    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.
    0 讨论(0)
  • 2020-12-25 11:51

    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).

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题