Questions tagged [android-jetpack-compose]

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.

Filter by
Sorted by
Tagged with
189 votes
12 answers
121k views

How to get Context in Jetpack Compose

fun createListItem(itemIndex: Int) { Padding(left = 8.dp, right = 8.dp, top = 8.dp, bottom = 8.dp) { FlexRow(crossAxisAlignment = CrossAxisAlignment.Center) { expanded(1.0f) { ...
Mr. Tayyab MuGhal's user avatar
182 votes
13 answers
57k views

Type 'State<List<User>?>' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate

I'm trying to get a value from LiveData with observeAsState in jetpack compose, but I get a weird error Type 'State<List?>' has no method 'getValue(Nothing?, KProperty<*>)' and thus it ...
SNM's user avatar
  • 6,205
172 votes
9 answers
122k views

How to add Margin in Jetpack Compose?

How exactly can you add Margin in Jetpack Compose? I can see that there is a Modifier for padding with Modifier.padding(...) but I can't seem to find one for margins or am I blind? Someone guide me ...
Archie G. Quiñones's user avatar
165 votes
19 answers
226k views

Jetpack Compose - Column - Gravity center

I'm creating a layout with Jetpack Compose and there is a column. I would like center items inside this column: Column(modifier = ExpandedWidth) { Text(text = item.title) Text(text = ...
mac229's user avatar
  • 4,599
151 votes
24 answers
122k views

Hilt Unsupported metadata version in Kotlin

I was tried to run my code in Kotlin 1.5.10 With plugin as plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-kapt' id 'dagger.hilt.android.plugin' and dependencies as below ...
Lang Minh Nguyên's user avatar
128 votes
9 answers
64k views

How to disable ripple effect when clicking in Jetpack Compose

In Jetpack Compose, when you enable clickable {} on a modifier for a composable, by default it enables ripple effect for it. How to disable this behavior? Example code Row(modifier = Modifier ...
ImMathan's user avatar
  • 4,491
122 votes
10 answers
65k views

How to close the virtual keyboard from a Jetpack Compose TextField?

I'm using the Jetpack Compose TextField and I want to close the virtual keyboard when the user press the the action button (imeActionPerformed parameter). val text = +state { "" } TextField( ...
nglauber's user avatar
  • 21.6k
114 votes
12 answers
136k views

How to load Image from drawable in Jetpack compose?

I have tried below code but it reflects nothing in the UI, I'm missing anything here? class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { ...
Maddy's user avatar
  • 4,825
111 votes
7 answers
35k views

Content padding parameter it is not used

I recently started working with Jetpack Compose. I've got the following composable: @Composable fun SearchScreen(navController: NavHostController) { Scaffold( topBar = { SearchBar() }, ...
BenjyTec's user avatar
  • 5,285
110 votes
5 answers
76k views

How to use Compose inside Fragment?

The documentation describes how to create UI Jetpack Compose inside Activity. class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(...
Nurseyit Tursunkulov's user avatar
107 votes
3 answers
57k views

Android Jetpack Compose Icons doesn't contain some of the material icons

There're many oft-used material icons in androidx.compose.material.icons.Icons but some are missing. Just as an example there is no print icon. ... import androidx.compose.material.Icon import ...
Valeriy Katkov's user avatar
106 votes
7 answers
68k views

Request Focus on TextField in jetpack compose

How to auto focus on textfield in jetpack compose. When i click on textfield and start typing on it. Meantime when i click back button,then when i'm try to click on textfield, nothing happens. val ...
Mukul jangir's user avatar
  • 1,161
104 votes
6 answers
82k views

Screen width and height in Jetpack Compose

I am wondering how to get the screen width and height with Jetpack Compose? Is there any way you can retrieve the screen dimensions other than getWindowManager().getDefaultDisplay()?
AbdulMomen عبدالمؤمن's user avatar
101 votes
13 answers
27k views

Jetpack compose can't preview after updating to 1.0.0-rc01

this happened to me only when I updated to 1.0.0-rc01. it says: The following classes could not be found: - androidx.compose.ui.tooling.preview.ComposeViewAdapter (Fix Build Path, Edit XML, Create ...
Karim Sinouh's user avatar
  • 1,562
99 votes
2 answers
20k views

var value by remember { mutableStateOf(default) } produce error, why?

I'm referring to the example in https://developer.android.com/jetpack/compose/state. When I code var expanded by remember { mutableStateOf(false) } It errors stating Type 'TypeVariable(T)' has no ...
Elye's user avatar
  • 57.3k
95 votes
6 answers
47k views

What is the difference between "remember" and "mutableState" in android jetpack compose?

I'm new in jetpack compose and trying to understand the difference between remember and mutableStateOf In other words the deference between this line val text = remember{ mutableStateOf("") ...
Ahmed Abdalla's user avatar
94 votes
13 answers
51k views

Jetpack Compose Text hyperlink some section of the text

How can i add hyperlink to some section of the text of Text component? With buildAnnotatedString i can set link section blue and underlined as in image below, but how can i also turn that section ...
Thracian's user avatar
  • 55.8k
93 votes
3 answers
48k views

When should I use Android Jetpack Compose's Surface composable?

There's a Surface composable in Jetpack Compose which represents a material surface. A surface allows you to set up things like background color or border but it seems that the same might be done ...
Valeriy Katkov's user avatar
90 votes
4 answers
49k views

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 ...
Valeriy Katkov's user avatar
90 votes
7 answers
26k views

Bottom Nav Bar overlaps screen content in Jetpack Compose

I have a BottomNavBar which is called inside the bottomBar of a Scaffold. Every screen contains a LazyColumn which displays a bunch of images. For some reason when I finish scrolling, the BottomNavBar ...
Gianluca Veschi's user avatar
88 votes
9 answers
97k views

background color on Button in Jetpack Compose

Button(backgroundColor = Color.Yellow) { Row { Image(asset = image) Spacer(4.dp) Text("Button") } } I can not figure out why I can't use background color on ...
shotmeinthehead's user avatar
88 votes
6 answers
109k views

How to create rounded border Button using Jetpack Compose

I need to add border with rounded corner in Button using Jetpack Compose Like :
Sanjayrajsinh's user avatar
87 votes
1 answer
59k views

How can I specify an exact amount of spacing between children in a Jetpack Compose Column?

I am trying to create a Column in Jetpack Compose with a specific amount of spacing between each child element, such as 10.dp. In SwiftUI, this is relatively simple. I would just create a VStack with ...
Eugene's user avatar
  • 3,866
86 votes
3 answers
33k views

Jetpack Compose - Unresolved reference: observeAsState

I'm learning Jetpack Compose and I was trying to make a View Model for my @Composable. In documentation (https://developer.android.com/codelabs/jetpack-compose-state#3) for observing state changes in ...
Valentin Stamate's user avatar
82 votes
13 answers
48k views

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, ...
René Jörg Spies's user avatar
80 votes
8 answers
76k views

Jetpack compose - how do I refresh a screen when app returns to foreground

I need to automatically refresh an Android Compose screen when the app returns to the foreground. I have an that requires permissions and location services. If the user has switched any of these off a ...
William's user avatar
  • 1,525
79 votes
9 answers
113k views

How to upgrade an Android project to Java 11

I am using the latest Android Studio Arctic Fox 2020.03.01 Canary 8 and AGP 7, and I want to convert my project to use Java 11. Apparently just doing the following does not work as mentioned on https:/...
azfar's user avatar
  • 791
78 votes
3 answers
35k views

Toggle password field jetpack compose

Hi I am trying to change visualTransformation dynamically when the user click on see password button. I can manage to filter password but couldn't achive to show in plain text. Any idea for that ? ...
clouddy's user avatar
  • 1,011
77 votes
24 answers
82k views

how to change statusbar color in jetpack compose?

how to make status bar color transparent in compose like here: it has the same color but with a little bit shade.
Nurseyit Tursunkulov's user avatar
77 votes
7 answers
80k views

Match Width of Parent in Column (Jetpack Compose)

By default, Column {} has the width of it's largest child element. How can I make all other elements to fit the width of the parent Column? If I use Modifier.fillMaxWidth() the elements will take up ...
Yannick's user avatar
  • 5,401
76 votes
8 answers
54k views

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 ...
Vipul Asri's user avatar
  • 9,063
74 votes
5 answers
97k views

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 ...
PandaPlaysAll's user avatar
73 votes
8 answers
32k views

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). ...
machfour's user avatar
  • 2,320
72 votes
2 answers
53k views

Draw a line in jetpack compose

Using XML layout, you could use a View object with colored background to draw a line. <View android:width="match_parent" android:height="1dp" android:background="#000000" /> How can ...
Mahdi-Malv's user avatar
  • 17.9k
71 votes
3 answers
58k views

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 ...
Valeriy Katkov's user avatar
70 votes
15 answers
45k views

Jetpack Compose on Kotlin 1.5.0

I've updated to Kotlin 1.5 last week, and after yesterday having seen the intention of Google to make Jetpack Compose the preferred option for designing UIs, I wanted to do some testing. The issue is ...
Arnyminer Z's user avatar
  • 5,983
70 votes
5 answers
29k views

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: <EditText android:layout_width="wrap_content" ...
Cristan's user avatar
  • 13.2k
69 votes
7 answers
85k views

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/...
Corey Waldon's user avatar
69 votes
4 answers
45k views

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 ...
Christer's user avatar
  • 2,926
68 votes
9 answers
42k views

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 ...
Mahdi-Malv's user avatar
  • 17.9k
68 votes
4 answers
69k views

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<String> = listOf("Android", "there&...
Thracian's user avatar
  • 55.8k
68 votes
5 answers
45k views

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(...
AouledIssa's user avatar
  • 2,684
68 votes
5 answers
43k views

How to use string resources in Android Jetpack Compose?

Let's say I have the following strings.xml resource file: <resources> <!-- basic string --> <string name="app_name">My Playground</string> <!-- basic ...
Valeriy Katkov's user avatar
68 votes
9 answers
38k views

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 ...
nasibeyyubov's user avatar
  • 2,215
67 votes
18 answers
35k views

Android Compose: How to use HTML tags in a Text view

I have as string from an outside source that contains HTML tags in this format: "Hello, I am <b> bold</b> text" Before Compose I would have CDATA at the start of my HTML String, ...
William's user avatar
  • 1,525
67 votes
1 answer
24k views

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 ...
Ebin Joy's user avatar
  • 2,950
65 votes
3 answers
80k views

How do I create a Jetpack Compose Column where a middle child is scrollable but all of the other children are always visible?

I am creating a Jetpack Compose Dialog that contains a Column where all of the elements should always be visible, except for the third element, which is a Text that should be scrollable if the text ...
Eugene's user avatar
  • 3,866
63 votes
9 answers
76k views

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 ...
Rohit Jakhar's user avatar
  • 1,328
63 votes
5 answers
93k views

Error: "@Composable invocations can only happen from the context of a @Composable function"

I'm trying to show a toast message when clicking on a toolbar action, but I got this error @composable invocations can only happen from the context of a @composable function Code: @Composable fun ...
SNM's user avatar
  • 6,205
62 votes
10 answers
38k views

Button Long Press Listener in Android jetpack compose

I am having an Android Composable UI with a Button. How can I track button long press events? I got it working for the Text long press, but for Button, It is not working. Same way like below if I ...
SoftwareGuy's user avatar
  • 1,379

1
2 3 4 5
251