안드로이드

[안드로이드/Android] Compose TextField maxLength 설정하기

알통몬_ 2023. 3. 14. 12:58
반응형
// maxLength 설정하기
val maxLength = 8
OutlinedTextField(
    modifier = Modifier
        .fillMaxWidth()
        .padding(start = 24.dp, end = 24.dp),
    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
    leadingIcon = {
      	Icon(imageVector = Icons.Default.Person, contentDescription = "Birth")
    },
    value = birth,
    label = {
        Text("생년월일")
    },
    placeholder = {
        Text("19920822")
    },
    onValueChange = {
        if(it.text.length <= maxLength) birth = it
        else // 적절한 처리
    }
)

 

반응형