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。
参考: