Adaptive Layout for all Screen sizes in Android Jetpack Compose

Login Page :

    [![@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LoginPage(navController: NavController) {
    val context = LocalContext.current
    val homeScreen = remember { mutableStateOf(false) }
    val loginScreen = remember { mutableStateOf(false) }
    val mobileNumberState = remember { mutableStateOf("") }
    val showToastState = remember { mutableStateOf(false) }
    var buttonClicked by remember { mutableStateOf(false) }
    val keyboardController = LocalSoftwareKeyboardController.current

    // Check the length of the mobile number
    val isMobileNumberValid = mobileNumberState.value.length == 10 && mobileNumberState.value.isDigitsOnly()
    var isFieldFocused by remember { mutableStateOf(false) }
    val focusRequester = remember { FocusRequester() }

    Surface(
        color = Color(
            ContextCompat.getColor(
                context,
                R.color.pageBg
            )
        ),
        modifier = Modifier
            .fillMaxSize()
            .padding(10.dp)
    ) {
        Column(
            modifier = Modifier
                .fillMaxSize()
                .padding(horizontal = 16.dp)
                .background(Color.White)
                .verticalScroll(rememberScrollState())
        ) {
            Spacer(modifier = Modifier.weight(1f))
            Text(
                text = "Welcome Back!",
                modifier = Modifier.fillMaxWidth(),
                textAlign = TextAlign.Center,
                style = MaterialTheme.typography.headlineMedium,
                fontFamily = regular,
                color = colorResource(id = R.color.scaapp),
            )
            Spacer(modifier = Modifier.height(8.dp))
            Text(
                text = "Let’s get Started",
                modifier = Modifier.fillMaxWidth(),
                textAlign = TextAlign.Center,
                style = MaterialTheme.typography.headlineSmall,
                color = colorResource(id = R.color.splashtext),
                fontFamily = regular
            )
            Spacer(modifier = Modifier.height(24.dp))
            Image(
                painter = painterResource(id = R.drawable.login), // Replace 'login' with your drawable file name
                contentDescription = "Splash Image",
                modifier = Modifier
                    .fillMaxWidth()
                    .aspectRatio(1f)
                    .align(Alignment.CenterHorizontally)
            )
            Spacer(modifier = Modifier.height(24.dp))
            OutlinedTextField(
                value = mobileNumberState.value,
                keyboardOptions = KeyboardOptions(
                    capitalization = KeyboardCapitalization.None,
                    autoCorrect = true,
                    keyboardType = KeyboardType.Number,
                    imeAction = ImeAction.Done
                ),
                label = {
                    Row(
                        verticalAlignment = Alignment.CenterVertically,
                        modifier = Modifier.fillMaxWidth()
                    ) {
                        Text("+91 ", fontFamily = semibold)
                        Text(
                            text = "Enter Your Mobile Number",
//                            style = MaterialTheme.typography.bodySmall,
                            color = Color(
                                ContextCompat.getColor(
                                    context,
                                    R.color.placeholderColor
                                )
                            ),
                            maxLines = 1,
                        )
                    }
                },
                onValueChange = {
                    if (it.length <= 10) {
                        mobileNumberState.value = it.filter { char -> char.isDigit() } // This also ensures the input is only digits
                    }
                },
                modifier = Modifier
                    .fillMaxWidth()
                    .focusRequester(focusRequester)
                    .onFocusChanged { focusState ->
                        isFieldFocused = focusState.isFocused
                    },
                colors = TextFieldDefaults.outlinedTextFieldColors(
                    focusedBorderColor = if (isFieldFocused) {
                        if (mobileNumberState.value.length == 10) colorResource(id = R.color.scaapp) else Color.Red
                    } else colorResource(id = R.color.fieldBorder),
                    unfocusedBorderColor = colorResource(id = R.color.fieldBorder)
                )
            )
            Spacer(modifier = Modifier.height(16.dp))
            Button(
                onClick = {
                    val mobileNumber = mobileNumberState.value
                    if (mobileNumber.length == 10 && mobileNumber.isDigitsOnly()) {
                        showToastState.value = false
                        buttonClicked = true
                    } else {
                        showToastState.value = true
                        keyboardController?.hide()
                    }
                },
                shape = RoundedCornerShape(5.dp),
                modifier = Modifier
                    .height(50.dp)
                    .fillMaxWidth(),
               colors = ButtonDefaults.buttonColors(
                    containerColor = if (isMobileNumberValid) colorResource(R.color.scaapp) else colorResource(R.color.buttonDisable), // Set the background color
                    contentColor = Color.White // Set the text color
                )
            ) {
                Text("Sign in")
            }
            Spacer(modifier = Modifier.height(16.dp))
            Row(modifier = Modifier.align(Alignment.CenterHorizontally)) {
                Text(
                    "Don't have an account?",
                    color = colorResource(id = R.color.black),
                    fontFamily = regular
                )
                Text(
                    " Register here",
                    modifier = Modifier.clickable { navController.navigate(ROUTES.SIGNUP.name) },
                    color = colorResource(id = R.color.scaapp),
                    fontFamily = regular
                )
            }
        }
    }

    val prefDataStore = PreferenceDataStore(LocalContext.current)
    val accesstoken = runBlocking { prefDataStore.userName.first() }

    if (accesstoken.isEmpty()) {
        loginScreen.value = true
    } else {
        LaunchedEffect(true) {
            withContext(Dispatchers.IO) {
                prefDataStore.getDetails().collect {
                    if (it.name != "") {
                        withContext(Dispatchers.Main) {
                            homeScreen.value = true
                            navController.navigate(ROUTES.HOME.name)
                        }
                    } else {
                        withContext(Dispatchers.Main) {
                            navController.navigate(ROUTES.LOGIN.name)
                        }
                    }
                }
            }
        }
    }
}

@Preview(showBackground = true, device = Devices.DEFAULT)
@Composable
fun LoginPagePreview() {
    SCATheme {
        val navController = rememberNavController()
        LoginPage(navController)
    }
}

UI Output

when I check my UI in Start Check UI mode , 115%, 130 %, 180 % and 200 % screen sizes are always weird

As you can see “Don’t have an account?” and ” Register here” are not in single line except 100 % phone screen size

I also checked in real devices too…issue still exists

I need to show full text in single line without …

“Enter Your Mobile Number” is also issue in many screens as you can see in image

How to adaptable for all screen sizes in android jetpack compose

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật