androidkotlinandroid-jetpack-compose

How to unhide a TextField hidden by keyboard in Compose


So I have a main activity with 3 TextFields that are offset from the top because I am using tabbed navigation :

But what happens on small screens is that the keyboard hides the third textfield "Receiver".

How can I solve this ? Would using a ScrollableLayout be a solution (so the user could scroll to unhide the third textfield) ?


Solution

  • You can achieve this using Accompanist Insets library (UPD: link into the past) in three steps :-

    1- in your activity call setDecorFitsSystemWindows

    WindowCompat.setDecorFitsSystemWindows(window, false)
    

    2- call the ProvideWindowInsets function and wrap your content

    ProvideWindowInsets {
      // your content
    }
    

    3- call navigationBarsWithImePadding modifier in your content

    Full Example :-

    WindowCompat.setDecorFitsSystemWindows(window, false)  // step 1
    setContent {
        MaterialTheme {
            ProvideWindowInsets { // step 2
                Column(
                    modifier = Modifier
                        .navigationBarsWithImePadding() // step 3
                ) {
                    // your content
                }
            }
        }
    }