0

In AlertDialog on compose, do you know if its possible in the title field, to put an Image plus a title ?

I am trying to do something like

title = {
    Column(
        modifier = Modifier
            .fillMaxWidth()
    ) {
        Image(
            imageVector = image,
            contentDescription = null,
            modifier = Modifier
                .align(Alignment.CenterHorizontally)
            )
        Text("Title")
    }
},

text = {
    Text("test text")
},

The problem is : I think the title in AlertDialog has a specific size, so my Image is crop.

example

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
LikseN
  • 169
  • 1
  • 1
  • 7

1 Answers1

2

With M3 AlertDialog (androidx.compose.material3.AlertDialog) it works.

enter image description here

With M2 AlertDialog you can remove the title attribute and use the text attribute for the whole layout.

AlertDialog(
    onDismissRequest = {},
    text = {
        Column(Modifier.fillMaxWidth()){
            Image(
                painterResource(id = R.drawable.xxx),
                contentDescription = null,
                modifier = Modifier
                    .align(Alignment.CenterHorizontally)
            )
            Image(
                painterResource(id = R.drawable.xxx),
                contentDescription = null,
                modifier = Modifier
                    .align(Alignment.CenterHorizontally)
            )
            Text("Title")
            //.....
        }
    },
    buttons = {}
)
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Hi @Gabriele Mariotti, M3 alert dialog working fine, but always it is showing the bottom of the screen. How do we display the AlertDialog center of the screen? – Sathish Gadde Apr 07 '23 at 04:29
  • hi @Gabriele Mariotti sorry to bother you but if the image is the first element, it will be crop. It weird, but if I put the image between 2 text, it will work. Do you know how can i fix that? – Tai Nguyen Apr 14 '23 at 09:04