修改AlertDialog 按鈕的背景

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。


參考:

http://stackoverflow.com/questions/4604025/alertdialog-getbutton-method-gives-null-pointer-exception-android


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章