AlertDialog 提供了下面的方法來獲取Button對象:
public Button getButton (int whichButton)
Added in API level 3
Gets one of the buttons used in the dialog.
If a button does not exist in the dialog, null will be returned.
Parameters
whichButton The identifier of the button that should be returned. For example, this can be BUTTON_POSITIVE.
Returns
The button from the dialog, or null if a button does not exist.
獲取button對象後,就可以對button進行操作了。這裏注意,必須在AlertDialog.show()之後才能通過 getButton 獲取到button對象,否則返回爲null。
參考: