Jetpack [대왕놀] Switch in Compose

황제낙엽 2022.12.20 14:43 조회 수 : 4152

Android View 시스템의 Switch 는 Compose 에서 동일한 이름인 'Switch' 를 사용한다.

 

#

Switch 의 function signature 는 아래와 같다.

@Composable
@OptIn(ExperimentalMaterialApi::class)
fun Switch(
    checked: Boolean,
    onCheckedChange: ((Boolean) -> Unit)?,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    colors: SwitchColors = SwitchDefaults.colors()
)

 

#

Switch 의 일반적인 사용은 아래와 같다.

val isChecked by remember { mutableStateOf(false) }
Switch(
    value = isChecked,
    onCheckChanged = { isChecked = it },
)

 

#

Switch 의 Thumb color 변경은 colors 에 SwitchColors 를 assign 한다.

Switch(
	...
    colors = SwitchDefaults.colors(uncheckedThumbColor = Color.DarkGray),
)

 

번호 제목 글쓴이 날짜 조회 수
128 PC를 위한 최고의 안드로이드 에뮬레이터 황제낙엽 2023.01.18 3201
127 [Jetpack Compose UI / 상추님] GDG Jetpack compose 코드랩 수료 후기 (feat. 굿즈) 황제낙엽 2022.12.24 2399
126 [Jetpack Compose UI / kyj1991719] compose - Compose 이해 황제낙엽 2022.12.24 4068
125 [Jetpack Compose UI / 꾸준] Compose 가 뭔데...? 황제낙엽 2022.12.24 4079
124 [Jetpack Compose UI / IIVIKI] Compose 학습과 분석 황제낙엽 2022.12.24 4099
123 [Jetpack Compose UI] 스터디 시작하기 황제낙엽 2022.12.24 4038
122 [개발하는 정대리] 취준생을 위한 안드로이드 앱만들기 - 바텀네비게이션 뷰, 네비게이션 AAC file 황제낙엽 2022.12.22 3917
121 [개발하는 정대리] 취준생을 위한 안드로이드 앱만들기 - 뷰바인딩 file 황제낙엽 2022.12.22 3906
120 [개발하는 정대리] 취준생을 위한 안드로이드 앱만들기 - 라이브데이터 뷰모델 file 황제낙엽 2022.12.21 3872
119 [대왕놀] ImageButton in Compose (IconButton) 황제낙엽 2022.12.20 4152
118 [대왕놀] compose instrumentation test tutorial 황제낙엽 2022.12.20 4037
» [대왕놀] Switch in Compose 황제낙엽 2022.12.20 4152
116 [대왕놀] EditText in Compose (TextField) 황제낙엽 2022.12.20 4102
115 [대왕놀] margin in Compose 황제낙엽 2022.12.20 4138
114 [대왕놀] modifier in compose 황제낙엽 2022.12.20 4225
113 [대왕놀] Button in Compose file 황제낙엽 2022.12.20 4269
112 [대왕놀] TextView in Compose (Text) 황제낙엽 2022.12.20 4128
111 [대왕놀] ImageView in Compose (Image) 황제낙엽 2022.12.20 4069
110 [대왕놀] LinearLayout in Compose (Row, Column) 황제낙엽 2022.12.20 4205
109 [대왕놀] Introduction to Jetpack compose 황제낙엽 2022.12.20 4010