How can I set the order of the positive and negative buttons in AlertDialog?

后端 未结 8 1732
挽巷
挽巷 2021-02-05 06:05

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 i

8条回答
  •  一整个雨季
    2021-02-05 06:32

    Unfortunately, I don't believe you can. However, 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 you can turn the different buttons into whatever you want. What you're seeing here is the order having switched (ordering from this answer):

    • On devices prior to ICS, the button order (left to right) was POSITIVE - NEUTRAL - NEGATIVE.
    • On newer devices using ICS, the button order (left to right) is now NEGATIVE - NEUTRAL - POSITIVE.

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

提交回复
热议问题