avatarRafał Zowal

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3571

Abstract

ose</i></a></li><li><a href="https://levelup.gitconnected.com/jetpack-compose-chapter-11-selection-ui-components-checkboxes-switches-radio-buttons-efffe12a6132"><b>Chapter 12: </b><i>Tick and Pick: Mastering Checkboxes & Radio Buttons</i></a></li><li><b>Chapter 13: <a href="https://readmedium.com/jetpack-compose-chapter-13-using-a-scaffold-layout-10b7094abe78"></a></b><a href="https://readmedium.com/jetpack-compose-chapter-13-using-a-scaffold-layout-10b7094abe78"><i>The Scaffold Tower: Constructing Complex Layouts with Ease</i></a></li><li><a href="https://levelup.gitconnected.com/jetpack-compose-chapter-13-easy-guide-to-displaying-lists-with-lazy-layouts-c56c2c23fa5f"><b>Chapter 14 </b><i>The Lazy River: Displaying Lists with Lazy Layouts</i></a></li><li><a href="https://readmedium.com/jetpack-compose-chapter-15-mastering-state-management-91d95c0513ce"><b>Chapter 15: </b><i>The State of Code Magic: Managing UI State in Jetpack Compose</i></a></li><li><a href="https://readmedium.com/jetpack-compose-chapter-16-a-comprehensive-guide-to-understanding-recomposition-5d152f1e458d"><b>Chapter 16: </b><i>The Magic Behind the Curtain: Understanding Recomposition</i></a></li></ul><figure id="90e7"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*He9OqEY0v-xvqOfHB3G8DQ.png"><figcaption>(Image by Author having full rights)</figcaption></figure><h1 id="8621">The Enchanted Text Class</h1><p id="b31a">In the fantastical realm of Jetpack Compose, select a <code>Text</code> class and your words transform into a magical spell, appearing just as you command. To become a true wizard of this realm, understand these mystical parameters and how they summon your words into being:</p><ul><li><code><b>modifier</b></code>: The magical accessory of your choice that molds and shapes your text. Think of Modifiers as your spell book, ready to manipulate layout, add a sprinkle of padding or conjure up some style. You don’t have to be selective, feel free to chain modifiers together to conjure up your perfect text spell. It's your magic wand, guiding you through the UI wonderland.</li><li><code><b>text</b></code>: The spell's substance – the words you wish to display within your magical UI portal. It could be an enchanting hello or the details of a mystical creature. Whatever it is, <code>text</code> is the magic chant of your spell.</li><li><code><b>style</b></code>: The enchanting attire your text dons to align with your app's theme. The <code>style</code> parameter is like the robes of a wizard that sets the tone and appearance of your text in its mystical UI realm. Control the font, size, color, and more to tailor your words to the perfect appearance.</li><li><code><b>fontWeight</b></code>: How heavy you want your text spell to hit. Like the weight of a wand influences the power of its spell, <code>fontWeight</code> alters the emphasis of your text, making it as bold or as light as you wish. This parameter is your tool to ensure your text spell captures just the right amount of attention.</li></ul><h1 id="81db">Real-world Example:</h1><div id="4133"><pre><span class="hljs-meta">@Composable</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">EnchantBuffDisplay</span><span class="hljs-params">( artifactId: <span class="hljs-type">Int</span>? = <span class="hljs-number">0</span> <span class="hljs-comment">// Choose your artifact wisely</span> )</span></span> { <span class="hljs-comment">// Summon the legendary buff from the ancient codex</span> <span class="hlj

Options

s-keyword">val</span> legendaryBuff = summonBuff()[artifactId ?: <span class="hljs-number">0</span>] Column( modifier = Modifier .padding(top = <span class="hljs-number">96.</span>dp, start = <span class="hljs-number">16.</span>dp, end = <span class="hljs-number">16.</span>dp), ) { Text( modifier = Modifier.fillMaxWidth(), textAlign = TextAlign.Center, <span class="hljs-comment">// The name of the buff, echoing through the ages</span> text = legendaryBuff.name, style = MaterialTheme.typography.displaySmall, fontWeight = FontWeight.ExtraBold ) Text( <span class="hljs-comment">// A herald announces the arrival of the buff's lore</span> text = <span class="hljs-string">"Buff Lore"</span>, style = MaterialTheme.typography.bodyLarge, modifier = Modifier.padding(top = <span class="hljs-number">50.</span>dp) ) Text( <span class="hljs-comment">// Unravel the mystic description of your newly acquired powers</span> modifier = Modifier.padding(top = <span class="hljs-number">16.</span>dp), text = legendaryBuff.description, style = MaterialTheme.typography.bodyMedium, fontWeight = FontWeight.Medium ) } }

<span class="hljs-meta">@Composable</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">BuffAttributesDisplay</span><span class="hljs-params">( <span class="hljs-meta">@DrawableRes</span> symbol: <span class="hljs-type">Int</span>, <span class="hljs-comment">// Every buff carries its unique symbol</span> essence: <span class="hljs-type">String</span>, <span class="hljs-comment">// The essence of the buff</span> symbolColor: <span class="hljs-type">Color</span> <span class="hljs-comment">// The color that best represents the buff's power</span> )</span></span> { Row(modifier = Modifier.padding(<span class="hljs-number">16.</span>dp), verticalAlignment = Alignment.CenterVertically) { Icon( painter = painterResource(id = symbol), contentDescription = essence, tint = symbolColor ) Spacer(modifier = Modifier.width(<span class="hljs-number">8.</span>dp)) Text( text = essence, style = MaterialTheme.typography.bodyMedium, fontWeight = FontWeight.Medium ) } } </pre></div><p id="d8b7">Great job, our application is beginning to take shape. In the next episode, we will learn more about how we can organize our application uisng advanced <code>Row</code> and <code>Column</code> modifiers.</p><h1 id="9ff4">Stackademic 🎓</h1><p id="4f49">Thank you for reading until the end. Before you go:</p><ul><li>Please consider <b>clapping</b> and <b>following</b> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><b>X</b></a><b> | <a href="https://www.linkedin.com/company/stackademic">LinkedIn</a> | <a href="https://www.youtube.com/c/stackademic">YouTube</a> | <a href="https://discord.gg/in-plain-english-709094664682340443">Discord</a></b></li><li>Visit our other platforms: <a href="https://plainenglish.io"><b>In Plain English</b></a><b> | <a href="https://cofeed.app/">CoFeed</a> | <a href="https://venturemagazine.net/">Venture</a> | <a href="https://blog.cubed.run">Cubed</a></b></li><li>More content at <a href="https://stackademic.com"><b>Stackademic.com</b></a></li></ul></article></body>

TRANSFORM YOUR APP DEVELOPMENT JOURNEY

Jetpack Compose — Chapter 6: Adding Text

A Comprehensive Guide for a UI on Android Development

Credit: https://android-developers.googleblog.com/2022/07/jetpack-compose-1-2-is-now-stable.html

Table od contents:

  1. Introduction An overview of the guide, setting the stage for what’s to come.
  2. Our Enchanted Journey Through Jetpack Compose A creative and engaging walkthrough of Jetpack Compose fundamentals.
  3. The Enchanted Text Class A detailed exploration of the Text class and its attributes in Jetpack Compose.
  4. Real-world Example A practical demonstration of implementing the Text class within an app

Introduction:

Now, you will learn how to add Texts and order Composables within your application.

So there are no super secrets on how to do it; it is elementary as you will use a SwiftUI in iOS

Our Enchanted Journey Through Jetpack Compose

(Image by Author having full rights)

The Enchanted Text Class

In the fantastical realm of Jetpack Compose, select a Text class and your words transform into a magical spell, appearing just as you command. To become a true wizard of this realm, understand these mystical parameters and how they summon your words into being:

  • modifier: The magical accessory of your choice that molds and shapes your text. Think of Modifiers as your spell book, ready to manipulate layout, add a sprinkle of padding or conjure up some style. You don’t have to be selective, feel free to chain modifiers together to conjure up your perfect text spell. It's your magic wand, guiding you through the UI wonderland.
  • text: The spell's substance – the words you wish to display within your magical UI portal. It could be an enchanting hello or the details of a mystical creature. Whatever it is, text is the magic chant of your spell.
  • style: The enchanting attire your text dons to align with your app's theme. The style parameter is like the robes of a wizard that sets the tone and appearance of your text in its mystical UI realm. Control the font, size, color, and more to tailor your words to the perfect appearance.
  • fontWeight: How heavy you want your text spell to hit. Like the weight of a wand influences the power of its spell, fontWeight alters the emphasis of your text, making it as bold or as light as you wish. This parameter is your tool to ensure your text spell captures just the right amount of attention.

Real-world Example:

@Composable
fun EnchantBuffDisplay(
    artifactId: Int? = 0 // Choose your artifact wisely
) {
    // Summon the legendary buff from the ancient codex
    val legendaryBuff = summonBuff()[artifactId ?: 0]
    Column(
        modifier = Modifier
            .padding(top = 96.dp, start = 16.dp, end = 16.dp),
    ) {
        Text(
            modifier = Modifier.fillMaxWidth(),
            textAlign = TextAlign.Center,
            // The name of the buff, echoing through the ages
            text = legendaryBuff.name,
            style = MaterialTheme.typography.displaySmall,
            fontWeight = FontWeight.ExtraBold
        )
        Text(
            // A herald announces the arrival of the buff's lore
            text = "Buff Lore",
            style = MaterialTheme.typography.bodyLarge,
            modifier = Modifier.padding(top = 50.dp)
        )
        Text(
            // Unravel the mystic description of your newly acquired powers
            modifier = Modifier.padding(top = 16.dp),
            text = legendaryBuff.description,
            style = MaterialTheme.typography.bodyMedium,
            fontWeight = FontWeight.Medium
        )
    }
}

@Composable
fun BuffAttributesDisplay(
    @DrawableRes symbol: Int, // Every buff carries its unique symbol
    essence: String, // The essence of the buff
    symbolColor: Color // The color that best represents the buff's power
) {
    Row(modifier = Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) {
        Icon(
            painter = painterResource(id = symbol),
            contentDescription = essence,
            tint = symbolColor
        )
        Spacer(modifier = Modifier.width(8.dp))
        Text(
            text = essence,
            style = MaterialTheme.typography.bodyMedium,
            fontWeight = FontWeight.Medium
        )
    }
}

Great job, our application is beginning to take shape. In the next episode, we will learn more about how we can organize our application uisng advanced Row and Column modifiers.

Stackademic 🎓

Thank you for reading until the end. Before you go:

Programming
Android App Development
Software Development
Software Engineering
Jetpack Compose
Recommended from ReadMedium