2021年5月27日木曜日

Jetpack Compose で Spannable 的なことをしたいときは AnnotatedString を作る

buildAnnotatedString 関数が用意されている。 Text( text = buildAnnotatedString { append("By clicking blow you agree to our ") withStyle(style = SpanStyle(textDecoration = TextDecoration.Underline)) { append("Terms of Use") } append(" and consent \nto our ") withStyle(style = SpanStyle(textDecoration = TextDecoration.Underline)) { append("Privacy Policy") } append(".") }, ) SpanStyleParagraphStyle を指定する。 class SpanStyle( val color: Color = Color.Unspecified, val fontSize: TextUnit = TextUnit.Unspecified, val fontWeight: FontWeight? = null, val fontStyle: FontStyle? = null, val fontSynthesis: FontSynthesis? = null, val fontFamily: FontFamily? = null, val fontFeatureSettings: String? = null, val letterSpacing: TextUnit = TextUnit.Unspecified, val baselineShift: BaselineShift? = null, val textGeometricTransform: TextGeometricTransform? = null, val localeList: LocaleList? = null, val background: Color = Color.Unspecified, val textDecoration: TextDecoration? = null, val shadow: Shadow? = null ) { ... } class ParagraphStyle constructor( val textAlign: TextAlign? = null, val textDirection: TextDirection? = null, val lineHeight: TextUnit = TextUnit.Unspecified, val textIndent: TextIndent? = null ) { ... }


0 件のコメント:

コメントを投稿