Android 자료실/기능 개발
안드로이드/Android 의 (Compose Text) - 텍스트 선택하기
Victorywskim
2024. 1. 2. 04:38
반응형
기본적으로 컴포저블은 선택할 수 없습니다. 즉, 기본적으로 사용자가 앱에서 텍스트를 선택하고 복사할 수 없습니다. 텍스트 선택 기능을 사용 설정하려면 텍스트 요소를 SelectionContainer 컴포저블로 래핑해야 합니다.
@Composable
fun SelectableText() {
SelectionContainer {
Text("This text is selectable")
}
}
선택이 불가능하게 하려면 특정한 부분을 DisableSelection 컴포저블로 래핑해야 합니다.
@Composable
fun DisableSelectionText() {
DisableSelection {
Text("not selection")
}
}
선택 가능한 영역의 특정 부분에서 선택 기능을 사용 중지해야 하는 경우도 있습니다. 그런 경우에는 다음과 같이 래핑해야 합니다.
@Composable
fun PartiallySelectableText() {
SelectionContainer {
Column {
Text("This text is selectable")
Text("This one too")
Text("This one as well")
DisableSelection {
Text("But not this one")
Text("Neither this one")
}
Text("But again, you can select this one")
Text("And this one too")
}
}
}
이상입니다.

반응형