android:clickabletext
clickabletext
클릭커블 텍스트는 다음과 같이 만든다.
코드
- clickabletext.kt
@Composable fun ClickableTextComponent(value : String){ val initialText = "By continuing you accept our" val privacyPolicyText = "privacy Policy" val andText = "and" val termsandConditionsText = "Terms of Use" val annotatedString = buildAnnotatedString { append(initialText) withStyle(style = SpanStyle(color = Color.LightGray)) { pushStringAnnotation(tag = privacyPolicyText, annotation = privacyPolicyText) append(privacyPolicyText) } append(andText) withStyle(style = SpanStyle(color = Color.LightGray)) { pushStringAnnotation(tag = termsandConditionsText, annotation = termsandConditionsText) append(termsandConditionsText) } } ClickableText(text = annotatedString, onClick = {offset -> annotatedString.getStringAnnotations(offset, offset) .firstOrNull()?.also { span-> Log.d("ClickableTextComponent", "{$span}") } }) }
android/clickabletext.txt · 마지막으로 수정됨: 2024/07/28 20:19 저자 이거니맨
로그인