Jetpack Compose is Android’s modern toolkit for building native declarative UI made by Google. If you're targeting desktop with Compose for Desktop, use both this and [compose-desktop] tags.
Questions tagged [android-jetpack-compose]
10142 questions
65
votes
5 answers
Using rememberCoroutineScope() vs LaunchedEffect
Context
In Jetpack compose, we have the option of using rememberCoroutineScope() as well as using the LaunchedEffect composable in order to use coroutines / run suspend functions (show snackbars etc).
The convention I've adopted so far is to…

machfour
- 1,929
- 2
- 14
- 21
65
votes
8 answers
Color from hex string in jetpack compose
How to parse hex string e.g. #9CCC65 in Color class in jetpack compose.
P.S: option seem to be missing in jetpack compose package
Current Workaround:
Exported parseColor() method from standard Color class.
@ColorInt
fun parseColor(@Size(min = 1)…

Vipul Asri
- 8,903
- 3
- 46
- 71
64
votes
3 answers
How to show ellipsis (three dots) at the end of a Text line in Android Jetpack Compose?
Whether I use androidx.compose.foundation.text.BasicText or androidx.compose.material.Text, if there isn't enough space for a text it wraps to the next line, for example:
@Composable
fun EllipsisExample() {
Box(modifier = Modifier.width(160.dp))…

Valeriy Katkov
- 33,616
- 20
- 100
- 123
62
votes
7 answers
Weights in Jetpack compose
Is it possible to do weights in Jetpack Compose? For example, I'd like to set it up in such a way that one item is weighted as 1/3 of a layout, and the other takes up the remaining 2/3.
In the XML/ViewGroup style, you can achieve this using…

Corey Waldon
- 621
- 1
- 5
- 3
61
votes
2 answers
How to convert Dp to pixels in Android Jetpack Compose?
Most of Jetpack Compose API uses Dp as a dimensions unit, but sometimes a pixel value is required. How can I convert a dp value to px? Just for an example there's graphicsLayer() modifier that accepts translationX/Y arguments in pixels.

Valeriy Katkov
- 33,616
- 20
- 100
- 123
60
votes
5 answers
How to set the inputType for a TextField in Jetpack Compose
I'd like to restrict what the user can type in a TextField in Jetpack Compose. How do I do that?
The equivalent in xml is inputType:

Cristan
- 12,083
- 7
- 65
- 69
60
votes
4 answers
Android Jetpack compose gradient
Is it possible to draw a gradient over an image drawable using Jetpack Compose?
fun HeroCover() {
Column {
val image = +imageResource(R.drawable.edge_of_tomorrow_poster)
Container(modifier = Height(440.dp) wraps Expanded) {
…

AouledIssa
- 2,528
- 2
- 22
- 39
59
votes
1 answer
ComponentActivity vs AppCompatActivity in Android Jetpack Compose
When using Jetpack Compose, by default it extends the ComponentActivity class. But after trying some samples I switched to AppCompatActivity and everything seemed to work fine. So I wonder what the difference between these is. Do any additional…

Ebin Joy
- 2,690
- 5
- 26
- 39
58
votes
9 answers
Show custom alert dialog in Jetpack Compose
I am searching how create custom dialog in Jetpack Compose. In XML or Material Design we can create easily custom Dialog in which we can take user input, radio button etc. but i am not finding such thing in Jetpack Compose.

Rohit Jakhar
- 1,231
- 2
- 12
- 21
58
votes
5 answers
Jetpack Compose - Centering Text
I am using Jetpack Compose to create a simple flash card.
The idea is that you click the flash card and it will give you the answer.
However, I am stuck on a basic problem.
Unfortunately... I could not even find the official documentation, so my…

PandaPlaysAll
- 927
- 2
- 9
- 15
57
votes
2 answers
Jetpack Compose how to remove EditText/TextField underline and keep cursor?
Hi I need to remove the underline in my TextField because it look ugly when the TextField is circular. I have sat the activeColor to transparent, but then the cursor wont show (because it's transparent). How can I remove the underline/activeColor…

Christer
- 2,746
- 3
- 31
- 50
56
votes
10 answers
Why am I getting Backend Internal error: "Exception during IR lowering error" when using Jetpack Compose clickable-Modifier?
I am creating a custom Checkbox within a Surface which has a Modifier.clickable:
Surface(
modifier = Modifier
.clickable(
enabled = enabled,
interactionSource = interactionSource,
…

René Jörg Spies
- 1,544
- 1
- 10
- 29
56
votes
4 answers
What does Jetpack Compose remember actually do, how does it work under the hood?
Checking out codelab's basic tutorial there is a snippet to increase counter on button when clicked
@Composable
fun MyScreenContent(names: List = listOf("Android", "there")) {
val counterState = remember { mutableStateOf(0) }
…

Thracian
- 43,021
- 16
- 133
- 222
55
votes
9 answers
remove default padding on jetpack compose textfield
I want to customize TextField composable in Jetpack Compose. I am trying to achieve the result in the image below, but somehow TextField has some default paddings which i couldn't find how to change values of. I want to remove default paddings and…

nasibeyyubov
- 1,735
- 3
- 11
- 28
55
votes
9 answers
Compose-Navigation: Remove previous composable from stack before navigating
I'm using compose-navigation(alpha09) to handle the navigation between composables
I want to remove the Splash screen when moving to the next destination (I don't want the back pressed to get back to Splash)
Following attempts did not work as…

Mahdi-Malv
- 16,677
- 10
- 70
- 117