Search code examples
androidandroid-jetpack-composeimeandroid-bottomappbar

How to prevent soft keyboard from pushing custom BottomAppBar up?


I've tried all kinds of insets padding, window insets, consume insets (because I don't even really understand window insets)... nothing is working. I tried to look it up, but everyone has the exact opposite problem--they want their bottomm app bar to be pushed up by the keyboard; I don't, I want it to stay at the bottom and have the keyboard draw over top of it, I WANT the keyboard to obscure the bottom app bar.

I've recently added a search bar on the home screen (custom text field, not the compose search widget top bar thing) and when I click it, the bottom app bar gets pushed up when the keyboard comes up.

For reference, the compile and target SDK is 34, minimum 26; all dependencies are the latest (stable releases) as of today. Edge to edge is NOT enabled, I have no added any "safe drawing" or insets coding to the main activity of any kind, nor are there any WindowCompat codings added.

Here's the relevant code (minus my 500 different attempts at keeping the thing pinned to the bottom of the screen):

MainActivity (set content block):

setContent {
    val application = (application as CellarApplication)
    CompositionLocalProvider(LocalCellarApplication provides application) {
        TobaccoCellarTheme(preferencesRepo = application.preferencesRepo) {
            Surface(
                modifier = Modifier
                    .fillMaxSize(),
                color = MaterialTheme.colorScheme.background,
            ) {
                CellarApp()
            }
        }  
    }
}
        

HomeScreen scaffold:

Scaffold(
    modifier = modifier
        .nestedScroll(scrollBehavior.nestedScrollConnection),
    topBar = {
        CellarTopAppBar(
            title = stringResource(HomeDestination.titleRes),
            scrollBehavior = scrollBehavior,
            canNavigateBack = false,
            navigateToCsvImport = navigateToCsvImport,
            navigateToSettings = navigateToSettings,
            showMenu = true,
            exportCsvHandler = viewmodel,
        )
    },
    bottomBar = {
        CellarBottomAppBar(
            modifier = Modifier,
            navigateToStats = navigateToStats,
            navigateToAddEntry = navigateToAddEntry,
            currentDestination = HomeDestination,
            filterViewModel = filterViewModel,
        )
    },
    snackbarHost = {
        SnackbarHost(
            hostState = snackbarHostState,
            modifier = Modifier
                .padding(0.dp)
           snackbar = { Snackbar(it) }
        )
    },
) { innerPadding ->
    Column (
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Top,
        modifier = Modifier
            .fillMaxSize()
            .padding(top = 64.dp, bottom = 52.dp, start = 0.dp, end = 0.dp)
    ) {
    // rest of code calling screen content top level composables

Custom bottom app bar composable (defined in a different file where top app bar and app container composable are defined):

@Composable
fun CellarBottomAppBar(
    currentDestination: NavigationDestination?,
    modifier: Modifier = Modifier,
    navigateToHome: () -> Unit = {},
    navigateToStats: () -> Unit = {},
    navigateToAddEntry: () -> Unit = {},
    filterViewModel: FilterViewModel,
) {
    BottomAppBar(
        modifier = modifier
            .fillMaxWidth()
            .height(52.dp)
            .padding(0.dp),
        containerColor = primaryLight,
        contentColor = LocalCustomColors.current.navIcon,
        contentPadding = PaddingValues(0.dp),
    ) {
        Row(
            // rest of the bottom app bar code

Solution

  • Check your AndroidManifest.xml to see if android:windowSoftInputMode is set to adjustResize for your activity. For example:

    <activity
        android:name=".YourActivity"
        android:windowSoftInputMode="adjustResize">
    </activity>
    

    Change it to another value like adjustPan or adjustNothing may resolve your problem