안드로이드
Android 앱에 이미지 추가
jryou
2024. 6. 5. 14:59
튜토리얼과 다른 점.
1. text 호출 방법이 바뀜.
GreetingImage(
message = getString(R.string.happy_birthday_text),
from = "From Emma",
modifier = Modifier.padding(8.dp)
)
에서
GreetingImage(
message = stringResource(R.string.happy_birthday_text),
from = "From Emma",
modifier = Modifier.padding(8.dp)
)
stringResource를 사용하게끔 바뀜.
Compose 환경에서는 stringResource를 사용하는 것이 더 일반적이고, 전통적인 안드로이드 뷰 시스템에서는 getString을 사용.
Compose 내에서도 getString을 사용할 수 있지만, 가능하면 stringResource를 사용하는 것이 더 간결하고 직관적.
- Android 스튜디오의 Resource Manager 탭을 사용하면 이미지와 기타 리소스를 추가하고 구성할 수 있다.
- Image 컴포저블은 앱에 이미지를 표시하는 UI 요소
- Image 컴포저블에는 콘텐츠 설명이 있어야 앱의 접근성이 높아짐. 테스트 코드에는 콘텐츠 설명이 없음.
Image(
painter = image,
contentDescription = null,
contentScale = ContentScale.Crop,
alpha = 0.5F
)