Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- androidStudio
- 백준
- pandas
- ProGuard
- Rxjava
- boj
- AWS
- 암호학
- activity
- android
- Codeforces
- Compose
- 프로그래머스
- 쿠링
- Python
- 코드포스
- textfield
- 코루틴
- Hilt
- relay
- Coroutines
- MyVoca
- Gradle
- Kotlin
- MiTweet
- GitHub
- architecture
- TEST
- Coroutine
- livedata
Archives
- Today
- Total
이동식 저장소
Compose에서 시스템 폰트 크기 확인하기 본문
``Density`` 객체에는 ``Float`` 타입의 ``fontScale`` 프로퍼티가 선언되어 있다. 공식 문서에서는 다음과 같이 설명하고 있다.
The logical density of the display. This is a scaling factor for the Dp unit.
시스템 설정의 ``글자 크기`` 항목이 바로 이 fontScale을 설정하는 것이다. UI에서 설정한 ``sp`` 값에 fontScale을 곱하면 실제로 UI에 보일 글씨 크기를 얻을 수 있다. 기본값은 1.0이고, 최댓값은 2.0이다.
블린더 앱에서는 ``fontScale``의 값에 따라 서로 다른 UI를 보여주었다. fontScale이 일정 값 이상이라면 기본 UI 대신 저시력 UI를 보여준다. 저시력 UI는 예쁜 그래픽보다는 정보 전달을 우선 고려하여 개발하였다.
val Density.isLargeFont: Boolean
@Composable get() = this.fontScale >= 1.6
if (LocalDensity.current.isLargeFont) {
// 저시력 모드
NutrientList(
nutrients = importantNutrients,
modifier = modifier,
)
} else {
// 일반 모드
NutrientChipGrid(
nutrients = importantNutrients,
modifier = modifier,
)
}
극단적으로는 ``fontScale``의 값마다 서로 다른 UI를 적용할 수도 있겠지만, 대부분의 상황에서는 일반 UI, 저시력 UI 2개만으로 충분할 것 같다.
참고자료
Density | Android Developers
androidx.compose.desktop.ui.tooling.preview
developer.android.com
'Primary > Compose' 카테고리의 다른 글
Compose TextField를 커스터마이징해 보자 (0) | 2024.04.30 |
---|---|
Icon vs. Image (0) | 2024.04.07 |
TextField에 default string을 줘도 커서가 맨 앞으로 가는 이유 (2) | 2024.02.28 |
Compose에서 Icon의 크기를 IconButton만큼 키우고 싶다면? (0) | 2024.02.06 |
ViewModel에 너무 많은 책임을 지우지 말 것 (0) | 2024.02.04 |
Comments