My Application is fully Composable and I do not want to use View,
my objective is to show a specific Composable at the bottom of the screen, and if the keyboard appears than on top of the keyboard, is it possible?
Thanks!
I was trying to use
activity?.let {
WindowCompat.setDecorFitsSystemWindows(it.window, false)
}
ProvideWindowInsets {
content{}
}
apparently it is deprecated, here is the solution:
https://google.github.io/accompanist/insets/
modifier = Modifier
.fillMaxSize().imePadding().systemBarsPadding()
Related
I have a BottomSheetScaffold(), on button push the bottomsheet is coming up, all is working fine, but i want to prevent the user from swiping down the bottomsheet. Instead a button on the bottomsheet is use to close it on click.
I see the option drawerGesturesEnabled, but this not doing anything.
You can set its sheetGesturesEnabled parameter to false
BottomSheetScaffold(
sheetGesturesEnabled = false,
…
…
Am I missing something, but why Scaffold's TopAppBar moves out of the screen when keyboard appears?
I have a simple layout:
setContent {
MyTheme {
Scaffold(topBar = { MyTopAppBar() }) {
ScaffoldContent(it)
}
}
}
Where ScaffoldContent is just a Column with a TextField.
When I press a TextField, keyboard opens and moves everything up . How can I make the bar stick at the top?
Tried:
android:windowSoftInputMode="adjustResize" or "adjustPan"
Instead of Scaffold use a Column and add elements there, but moves anyway
Expected:
TopAppBar to be at the top all the time, like in our Views system
I have some items in a modal sheet layout and when I press an Item, I navigate to another screen. However, when I press back button in the detail screen, the modal sheet reappears with a flashing behavior. I think this is because of recomposition but is there a way to prevent the recomposition without using a box and hiding-revealing the other screen? Any help is appreciated.
Maybe you need to pop the bottom sheet from the backstack?
When navigating to your detail screen from the bottom sheet, get the instance of the BottomSheetNavigator you used to create the ModalBottomSheetLayout and do:
bottomSheetNavigator.popBackStack(backstackEntry, true)
You get the backstackEntry from the lambda when calling bottomSheet(route)
I have a screen with TextField and, ideally, I want to achieve the following behavior:
TextField should become focused as soon as the screen is shown and the software keyboard must appear
User can clear the focus and hide the software keyboard (or I can do it programatically)
When device is rotated, focus and the keyboard must retain their state (so, for example, if the keyboard was shown, it should stay)
Currently I can't even get keyboard to always show up after screen rotation.
I have the following code, but it does this: for example, if the screen was initially opened in portrait mode, when rotated into landscape the keyboard hides, but when rotated back to portrait it returns back. Focus always stays as expected.
val focusRequester = remember { FocusRequester() }
TextField(
value = ...,
onValueChange = { ... },
modifier = Modifier.focusRequester(focusRequester)
)
focusRequester.requestFocus()
Modifying it as follows works, but I don't really like this delay:
...
val keyboard = LocalSoftwareKeyboardController.current
LaunchedEffect(Unit) {
focusRequester.requestFocus()
delay(1000L) // Just a magic constant which works on my device
keyboard?.show()
}
How can I achieve the described behavior? I see that Google Search screen acts almost like I want, though, it doesn't remember keyboard's state and always opens it after rotation.
Is there any way to prevent cut, copy, paste in TextField in Android Jetpack Compose?
I tried Modifier's pointerInput but it is not working.
Modifier.pointerInput(Unit) {
detectTapGestures(onLongPress = {
Toast.makeText(context, "long pressed", Toast.LENGTH_SHORT).show()
})
}
Is there any way to achieve this in Compose?