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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
| @Composable fun TextDemo() { Column() { Text(stringResource(id = R.string.app_name)) Text( text = "你好呀陌生人,这是一个标题,不是很长,因为我想不出其他什么比较好的标题了", modifier = Modifier.width(200.dp), maxLines = 1, overflow = TextOverflow.Ellipsis ) Text(text = "Hello World", color = Color.Blue) Text(text = "Hello World", fontSize = 30.sp) Text(text = "Hello World", fontStyle = FontStyle.Italic) Text(text = "Hello World", fontWeight = FontWeight.Bold) Text( text = "Hello World Hello World\nHello World", textAlign = TextAlign.Center ) Text( text = "Hello World", textAlign = TextAlign.Center, modifier = Modifier .width(100.dp) .height(30.dp) ) Text(text = "Hello World", fontFamily = FontFamily.Serif) Text(text = "Hello World", fontFamily = FontFamily.SansSerif) val firaSansFamily = FontFamily( Font(R.font.firasans_light, FontWeight.Light), Font(R.font.firasans_regular, FontWeight.Normal) ) Text( text = "Hello World", fontFamily = firaSansFamily, fontWeight = FontWeight.Light ) Text( text = "Hello World", fontFamily = firaSansFamily, fontWeight = FontWeight.Normal ) Text( text = "Hello World", style = TextStyle(textDecoration = TextDecoration.LineThrough) ) Text( text = "Hello World", style = TextStyle(textDecoration = TextDecoration.Underline) ) Text( text = "Hello World", style = TextStyle( textDecoration = TextDecoration.combine( listOf( TextDecoration.LineThrough, TextDecoration.Underline ) ) ) ) Text(text = buildAnnotatedString { withStyle( style = SpanStyle( color = Color.Blue ) ) { append("H") } append("ello ") withStyle( style = SpanStyle( fontWeight = FontWeight.Bold, color = Color.Green ) ) { append("W") } append("orld") }) Text(text = buildAnnotatedString { withStyle( style = ParagraphStyle( lineHeight = 40.sp ) ) { withStyle( style = SpanStyle( color = Color.Yellow ) ) { append("Hello\n") } withStyle( style = SpanStyle( fontWeight = FontWeight.Bold, color = Color.Red ) ) { append("World\n") } append("Compose") } }) Text( text = "Hello World ".repeat(20), maxLines = 3 ) Text( text = "Hello World".repeat(20), maxLines = 3, overflow = TextOverflow.Ellipsis ) CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.high) { Text("这里是high强调效果") } CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) { Text("这里是medium强调效果") } CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.disabled) { Text("这里是禁用后的效果") } } }
|