2021年5月27日木曜日

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

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



0 件のコメント:

コメントを投稿