Images for AlertDialog buttons

后端 未结 6 1966
再見小時候
再見小時候 2021-01-11 14:19

Is it possible to add drawables to the positive, negative and neutral buttons of an AlertDialog? If yes, then how?

6条回答
  •  离开以前
    2021-01-11 15:20

    You can't add buttons in the onCreateDialog and MUST do it in the onPrepareDialog because AlertDialog are handled in a very special way by android :

    you actually don't really hold a reference to the real dialog when you use alert dialog, the object you get by using AlertDialog.Builder.create() is just a face to an inner controller.

    And before create is actually called, there is no such controller in the jvm. Just the facade. So, until this method is called (at the end of onCreateDialog if you let your activity manage its own dialogs), the real controller doesn't exist, and real buttons don't neither.

    brand new SOF commenter, Stéphane

提交回复
热议问题