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
175
votes
13 answers
Type 'State?>' 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
- ' has no method 'getValue(Nothing?,
KProperty<*>)' and thus it cannot serve as a delegate
Code
@Composable
fun…

SNM
- 5,625
- 9
- 28
- 77
166
votes
12 answers
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) {
Text("Item $itemIndex")
…

Mr. Tayyab MuGhal
- 1,791
- 2
- 10
- 11
142
votes
18 answers
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 = item.description)
}

mac229
- 4,319
- 5
- 18
- 24
137
votes
9 answers
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 please.
Thank you very much.

Archie G. Quiñones
- 11,638
- 18
- 65
- 107
117
votes
17 answers
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
dependencies {
...
//Dagger - Hilt
…

Lang Minh Nguyên
- 3,648
- 4
- 10
- 31
105
votes
8 answers
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(
value = text.value,
keyboardType =…

nglauber
- 18,674
- 6
- 70
- 75
96
votes
7 answers
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
.clickable { // action }
)

ImMathan
- 3,911
- 4
- 29
- 45
92
votes
2 answers
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 androidx.compose.material.icons.Icons
import…

Valeriy Katkov
- 33,616
- 20
- 100
- 123
92
votes
12 answers
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?) {
super.onCreate(savedInstanceState)
setContent…

Maddy
- 4,525
- 4
- 33
- 53
91
votes
2 answers
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 method 'getValue(Nothing?, KProperty<*>)' and thus…

Elye
- 53,639
- 54
- 212
- 474
91
votes
5 answers
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(savedInstanceState)
setContent {
Text("Hello…

Nurseyit Tursunkulov
- 8,012
- 12
- 44
- 78
89
votes
5 answers
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 عبدالمؤمن
- 19,419
- 17
- 57
- 65
87
votes
6 answers
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() },
content = {
Column(modifier =…

BenjyTec
- 1,719
- 2
- 12
- 22
87
votes
10 answers
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 Class)
my code:
@Composable
@Preview
fun…

Karim Sinouh
- 1,312
- 2
- 6
- 20
84
votes
7 answers
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 textState = remember {…

Mukul jangir
- 941
- 1
- 4
- 3