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
Related
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()
Created a LazyColumn with textFields and it seems to have issue with "android:windowSoftInputMode="adjustResize"parameter.
When clicking a text field that needs to move up so it won't be hidden behind keyboard, causes issues when using AdjustResize parameter. The keyboard will open and then close again. It seems that textfield has lost a focus when ui is doing adjustResize.
Simple code example:
LazyColumn(state = rememberLazyListState()) {
for (i in 1..20) {
item {
TextField(value = "item{$i}", onValueChange = {})
}
}
}
And in AndroidManifest.xml I have
<activity
android:name=".MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize"
...
Demo to show that keyboard is closed just after it opens. (This issue only happens when to click on item that needs adjustment to be visible when keyboard is open)
LazyColumn Textfield works correctly without AdjustResize focused item will be moved up and everything is fine. The reason why I would like to use AdjustResize is that in my actual app I have undo/redo buttons at the bottom of the screen and I would like to move them up when keyboard is opened, but it seems I need to use AdjustResize to make it work, but that brakes textFields.
So I was wondering how can I make LazyColumn TextFields to work with AdjustResize? (I'm using latest compose version: 1.3.1)
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.
I'm newbie in the flutter, and when I create a floating button in the navigation bar to show the record form. But when I try to input something to the textfield, the floating button not stay in the bottom (navigation bar)
floating button in the navigation bar
after input something to the textfields
Anyone can help me how to fix this? Thank you
By default, your Scaffold has been instructed to resize itself whenever a keyboard opens up.
This is controlled by the resizeToAvoidBottomInset property of the Scaffold.
When you set it to false, your Scaffold won't resize itself when a Keyboard is open causing your Scaffold to still take up the entire device height behind the Keyboard.
Use it like this,
Scaffold(
resizeToAvoidBottomInset: false