Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add drawable's next to textfield in jetpack compose?

I am trying to figure out how to add a drawable to a text within a textfield (OutlinedTextField) but without any success. I have already created a drawable in the drawable folder. Do I need to create a seperate composable to insert it or can I directly add it inside the textfield ?

This is my textfield in the composable:


        Spacer(modifier = Modifier.height(20.dp))
        OutlinedTextField(
            value = username.value,
            onValueChange = { newText ->
                username.value = newText
            },
            label = { Text(text = "Username") },
            placeholder = { Text("") }, // placeholder / hint
            modifier = Modifier
                .fillMaxWidth(180F)
        )

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use leadingIcon instead of placeHolder

           OutlinedTextField(
               value = username.value,
               onValueChange = { newText ->
                   username.value = newText
               },
               label = { Text(text = "Username") },
               leadingIcon = { Icon(imageVector = Icons.Default.Place, contentDescription = null)},
               modifier = Modifier
                   .fillMaxWidth(180F)
           )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading