Android: Difference between positive, negative, an

2019-02-02 03:31发布

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

5条回答
够拽才男人
2楼-- · 2019-02-02 03:43

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

查看更多
Summer. ? 凉城
3楼-- · 2019-02-02 03:50

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

查看更多
Lonely孤独者°
4楼-- · 2019-02-02 03:54

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

查看更多
手持菜刀,她持情操
5楼-- · 2019-02-02 04:05

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

Dialog specs

查看更多
戒情不戒烟
6楼-- · 2019-02-02 04:07

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.
查看更多
登录 后发表回答