Created
July 21, 2024 20:19
-
-
Save Khazbs/5138f20b9e1da497404680e8ece5ed8b to your computer and use it in GitHub Desktop.
How to wed Scaffold, LazyColumn and IME padding in Jetpack Compose edge-to-edge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.app | |
import android.os.Bundle | |
import androidx.activity.* | |
import androidx.activity.compose.setContent | |
import androidx.compose.foundation.layout.* | |
import androidx.compose.foundation.lazy.LazyColumn | |
import androidx.compose.material3.* | |
import androidx.compose.runtime.* | |
import androidx.compose.runtime.saveable.rememberSaveable | |
import androidx.compose.ui.Modifier | |
import com.example.app.ui.theme.ExampleTheme | |
class MainActivity : ComponentActivity() { | |
@OptIn(ExperimentalMaterial3Api::class) | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
enableEdgeToEdge() | |
setContent { | |
ExampleTheme { | |
Scaffold( | |
topBar = { | |
Row(Modifier.fillMaxWidth(), Arrangement.Center) { | |
var query by rememberSaveable { mutableStateOf("") } | |
SearchBar(query, { query = it }, {}, false, {}) {} | |
} | |
}, | |
content = { innerPadding -> | |
LazyColumn( | |
modifier = Modifier | |
.consumeWindowInsets(innerPadding) | |
.imePadding(), | |
contentPadding = innerPadding, | |
content = { items(30) { ListItem({ Text("Item #$it") }) } }, | |
) | |
}, | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment