Search code examples
android-jetpack-composeandroid-softkeyboardandroid-jetpackandroid-background

Jetpack Compose - stop background resizing with keyboard


I've added android:windowSoftInputMode="adjustResize" to my AndroidManifest.xml file to allow the textfield, button and text to move up, but the background is also re-sizing itself. How can I stop this from happening?

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {

            //Used to determine where the starting launch point of the app is
            val user by remember { mutableStateOf(Firebase.auth.currentUser) }
            AppNavigation(
                startDestination = if (user == null) {
                    ViewToDisplayKeys.SignInOrSignUp.toString()
                } else {
                    ViewToDisplayKeys.OnboardingStart.toString()
                }
            )

        }
    }
}



@Composable
fun AppNavigation(
    navController: NavHostController = rememberNavController(),
    startDestination: String = "signInOrSignUp"
) {
    NavHost(
        navController = navController,
        startDestination = startDestination
    ) {
        composable("signInOrSignUp") {
            SignInOrSignUpMasterView(navController = navController)
        }
        composable("onboarding") {
            OnboardingStartView(navController)
        }
    }
}   

enter image description here

enter image description here


Solution

  • Put it in the onCreate method, the code is as follows:

    class SignInOrSignUp : ComponentActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            getWindow().setBackgroundDrawableResource(R.drawable.sign_in_sign_up_background)
            setContent {
                AppTheme {
                    Box(modifier = Modifier.fillMaxSize()) {
                        SignInOrSignUpMasterView()
                    }
                }
    
            }
    
        }
    }
    
    
    @Composable
    fun SignInOrSignUpView() {
    
        Box {
    
            //Background image
            /*Image(
                painter = painterResource(id = R.drawable.sign_in_sign_up_background),
                contentDescription = null,
                contentScale = ContentScale.FillBounds,
                alpha = 0.50F,
                modifier = Modifier
                    .background(Color.White)
            )*/
    
    
            SignUpView()
        }
    
    }