From 4af1bf3b5ec5d06e12e234f46d213e504949dd80 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 5 Feb 2023 19:37:25 +0900 Subject: [PATCH] #4 - Working with Text --- .../java/com/codelab/theming/ui/start/Home.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ThemingCodelab/app/src/main/java/com/codelab/theming/ui/start/Home.kt b/ThemingCodelab/app/src/main/java/com/codelab/theming/ui/start/Home.kt index c0563a1..9fa883a 100644 --- a/ThemingCodelab/app/src/main/java/com/codelab/theming/ui/start/Home.kt +++ b/ThemingCodelab/app/src/main/java/com/codelab/theming/ui/start/Home.kt @@ -34,6 +34,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.heading import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.withStyle import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.codelab.theming.R @@ -46,9 +47,7 @@ import java.util.* fun Home() { val featured = remember { PostRepo.getFeaturedPost() } val posts = remember { PostRepo.getPosts() } - JetnewsTheme( - darkTheme = true - ) { + JetnewsTheme { Scaffold( topBar = { AppBar() } ) { innerPadding -> @@ -103,6 +102,7 @@ fun Header( ) { Text( text = text, + style = MaterialTheme.typography.subtitle2, modifier = Modifier .fillMaxWidth() .semantics { heading() } @@ -135,10 +135,12 @@ fun FeaturedPost( val padding = Modifier.padding(horizontal = 16.dp) Text( text = post.title, + style = MaterialTheme.typography.h6, modifier = padding ) Text( text = post.metadata.author.name, + style = MaterialTheme.typography.body2, modifier = padding ) PostMetadata(post, padding) @@ -154,6 +156,9 @@ private fun PostMetadata( ) { val divider = " • " val tagDivider = " " + val tagStyle = MaterialTheme.typography.overline.toSpanStyle().copy( + background = MaterialTheme.colors.primary.copy(alpha = 0.1f) + ) val text = buildAnnotatedString { append(post.metadata.date) append(divider) @@ -163,12 +168,15 @@ private fun PostMetadata( if (index != 0) { append(tagDivider) } - append(" ${tag.uppercase(Locale.getDefault())} ") + withStyle(tagStyle) { + append(" ${tag.uppercase(Locale.getDefault())} ") + } } } CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) { Text( text = text, + style = MaterialTheme.typography.body2, modifier = modifier ) }