sitelink1 https://aroundck.tistory.com/8189 
sitelink2  
sitelink3  

Android View 시스템의 TextView 는 Compose 에서 'Text' 에 매핑된다.

 

#

Text 는 아래와 같은 signature 를 갖고 있다.

fun Text(
    text: String,
    modifier: Modifier = Modifier,
    color: Color = Color.Unspecified,
    fontSize: TextUnit = TextUnit.Unspecified,
    fontStyle: FontStyle? = null,
    fontWeight: FontWeight? = null,
    fontFamily: FontFamily? = null,
    letterSpacing: TextUnit = TextUnit.Unspecified,
    textDecoration: TextDecoration? = null,
    textAlign: TextAlign? = null,
    lineHeight: TextUnit = TextUnit.Unspecified,
    overflow: TextOverflow = TextOverflow.Clip,
    softWrap: Boolean = true,
    maxLines: Int = Int.MAX_VALUE,
    onTextLayout: (TextLayoutResult) -> Unit = {},
    style: TextStyle = LocalTextStyle.current
)

 

#

Text 에 stringRes 를 지정하려면 stringResource 함수를 활용하자.

Text(
	text=stringResource(R.string.app_name),
)

 

#

Text 의 fontSize 지정은 fontSize parameter 를 활용한다. Int.sp 함수가 쓰인 것을 주목하자.

Text(
	text="Hello World",
	fontSize=18.sp,
)

 

#

Text 에 bold 를 추가하려면 fontWeight parameter 를 활용한다.

Text(
	text="Hello World",
	fontWeight = FontWeight.Bold,
)

FontWeight 에는 Thin, Light, Normal, Medium, Bold 와 함께 추가적인 값들 (ex. ExtraBold) 이 있으니 사용시 참고해서 사용하자.

 

#

Text 에 Android View 시스템의 gravity 값을 주려면, textAlign parameter 를 활용하자.

Text(
	text="Hello World",
	textAlign = TextAlign.End,
)

 

#

Text 를 singleLine 처리 하려면 maxLines parameter 를 활용하자.

Text(
	text="Hello World",
	maxLines=1,
)

 

#

Text 에 ellipsize(말줄임. android:ellipsize) 옵션을 주려면 overflow parameter 를 활용하자.

Text(
	text="Hello World",
	overflow=TextOverflow.Ellipsis,
)

TextOverflow 의 constant 는 Clip(잘라내기, 기본값), Ellipsis, Visible(bounds 를 넘어서도 그리는..) 이 있다.

 

#

Text 에 underline (밑줄) 옵션을 주려면 textDecoration parameter 를 활용하자.

Text(
	text="Hello World",
	textDecoration=TextDecoration.Underline,
)

TextDecoration 의 constant 는 None, Underline, LineThrough(취소선) 이 있다.

 

#

Text 에 italic (기울어진) 옵션을 주려면 fontStyle parameter 를 활용하자.

Text(
	text="Hello World",
	fontStyle=FontStyle.Italic,
)

 

#

Text 에 clickListener 를 주기 위해서는 Modifier.clickable 을 활용하자.

Text(
	text="Hello World",
    modifier=Modifier.clickable { /* .. */ },
)

 

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