修改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


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