Images for AlertDialog buttons

后端 未结 6 1967
再見小時候
再見小時候 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:15

    This can be done by getting a reference to the button using the getButton() method:

    alert.show();
    Button email = alert.getButton(AlertDialog.BUTTON_NEUTRAL);
    email.setBackgroundResource(R.drawable.email);
    

    Note that you must use the getButton() AFTER calling the show() method, otherwise you'll get a NullPointerException..

提交回复
热议问题