How to add an icon before each item in alert dialog?

后端 未结 4 461
灰色年华
灰色年华 2020-12-02 10:15

I am using an AlertDialog (see the below code) and would like to put an image before each text.

For example, email icon then text \"Email\", Facebook icon then text

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 10:40

    I like Tom Esterez's solution but recommend using the relative function instead for RTL support.

    So use this:

    tv.setCompoundDrawablesRelativeWithIntrinsicBounds(items[position].iconID, 0, 0, 0);
    

    instead of this:

    tv.setCompoundDrawablesWithIntrinsicBounds(items[position].iconID, 0, 0, 0);
    

提交回复
热议问题