14,276 questions
227
votes
13
answers
159k
views
How to get Context in Jetpack Compose
I am trying to show a Toast message when I click on the item, but how do I get the context to pass the Toast class?
fun createListItem(itemIndex: Int) {
Padding(left = 8.dp, right = 8.dp, top = 8....
211
votes
13
answers
71k
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 ...
204
votes
9
answers
158k
views
How can I 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?
193
votes
19
answers
282k
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 = ...
185
votes
28
answers
169k
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 ...
163
votes
13
answers
98k
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
...
146
votes
10
answers
128k
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()?
143
votes
10
answers
86k
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(
...
134
votes
8
answers
52k
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() },
...
132
votes
7
answers
95k
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 ...
131
votes
4
answers
92k
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 ...
130
votes
12
answers
169k
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?) {
...
126
votes
1
answer
90k
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 ...
123
votes
24
answers
77k
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 ...
123
votes
6
answers
91k
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(...