Android Dev/Compose / / 2021. 12. 7. 00:25

Compose - Text Trial / OutlinedTextField / Keyboard

textStyle = MaterialTheme.typography.body2,

 

option에 따른 중앙정렬/왼쪽정렬로 나누기 + textStyle 설정

 

 

 OutlinedTextField(
            value = text,
            onValueChange = {
                if(text.length <= limitLength){
                    onTextChanged(it)
                }else{
                    onTextChanged(it.substring(0 until limitLength))
                }
            },
//            label = { Text("Label") }, .align(Alignment.Center),
            modifier = Modifier.fillMaxWidth(),
            placeholder = {
                if(textCenterAlignment)
                    Text(hint,
                    modifier = Modifier.fillMaxWidth(),
                    textAlign = TextAlign.Center,
                    fontFamily = notosanFontFamily,
                    fontWeight = FontWeight.Normal)
                else
                    Text(hint,
                    modifier = Modifier.fillMaxWidth(),
                    textAlign = TextAlign.Start,
                    fontFamily = notosanFontFamily,
                    fontWeight = FontWeight.Normal)
            },
            singleLine = true,
            textStyle = if(textCenterAlignment) subtitle1Center else vlmTypography.subtitle1,
            shape = RoundedCornerShape(radius),
            colors = TextFieldDefaults.outlinedTextFieldColors(
                placeholderColor = ColorSomeGray,
                cursorColor = Color.Black,
                focusedBorderColor = ColorEditTextOutlinedUnfocused,
                unfocusedBorderColor = ColorEditTextOutlinedUnfocused
            )
        )

 

Textstyle 조정

val subtitle1Center = TextStyle(
    fontFamily = fonts,
    fontWeight = FontWeight.W500,
    lineHeight = 22.sp,
    textAlign = TextAlign.Center
)

 

 

 

키보드 설정 : 숫자만 보이게 하기

 

keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number),

 

 

 

글자수 제한하는 방법

val gatheringLocation =
    if(getheringNetworkData.metaData.gatheringLocation.length > 25) "${getheringNetworkData.metaData.gatheringLocation.take(25)}..."
    else getheringNetworkData.metaData.gatheringLocation

 

 

  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유