{"id":60211,"date":"2024-03-11T09:59:19","date_gmt":"2024-03-11T04:29:19","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=60211"},"modified":"2024-03-11T10:00:36","modified_gmt":"2024-03-11T04:30:36","slug":"jetpack-compose-tutorial-for-beginners-easy-to-follow-steps","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/jetpack-compose-tutorial-for-beginners-easy-to-follow-steps\/","title":{"rendered":"Jetpack Compose Tutorial For Beginners \u2013 Easy-to-Follow Steps"},"content":{"rendered":"<h4><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60261 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/banner_jetpack_compose_ui-1024x683.png\" alt=\"\" width=\"625\" height=\"417\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/banner_jetpack_compose_ui-1024x683.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/banner_jetpack_compose_ui-300x200.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/banner_jetpack_compose_ui-768x512.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/banner_jetpack_compose_ui-624x416.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/banner_jetpack_compose_ui.png 1500w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/h4>\n<h4>Join us in exploring Jetpack Compose\u2014a cutting-edge toolkit that simplifies the process of crafting native user interfaces.<\/h4>\n<p>This tutorial offers a comprehensive guide on utilizing various Jetpack Compose features such as <strong>Text<\/strong>, <strong>TextField<\/strong>, <strong>Preview<\/strong>, <strong>Column<\/strong>, <strong>Row<\/strong>, <strong>Button<\/strong>, <strong>Card<\/strong>, <strong>AlertDialog<\/strong>, and <strong>MaterialDesign<\/strong> elements. Let&#8217;s kick things off by creating a Jetpack Compose Project and delve into practical examples without delay. Join us in mastering Jetpack Compose for Android through real-world examples.<\/p>\n<p><strong>Kindly note:<\/strong> To leverage <strong>Jetpack Compose<\/strong>, it&#8217;s imperative to have the latest Canary version of <strong>Android Studio 4.2 installed<\/strong>. Visit the <strong>&#8220;https:\/\/developer.android.com\/studio\/preview &#8220;<\/strong> Android Studio Preview page to acquire the most recent Canary version and proceed with the creation of an Empty Compose Activity.<\/p>\n<h2 class=\"graf--h2\">Composable Function<\/h2>\n<p>In Jetpack Compose, the UI of your app is defined programmatically using Composable functions. This eliminates the need for XML layout files. To create a composable function, simply apply the <strong>@Composable<\/strong> annotation to the function name. The basic syntax of a Composable function is as follows:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60213 size-medium\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/composable-300x211.png\" alt=\"\" width=\"300\" height=\"211\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/composable-300x211.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/composable-624x440.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/composable.png 738w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Now that you understand the concept of Composable Functions and have learned how to create them with the <strong>@Composable<\/strong> annotation, let&#8217;s proceed to explore an example involving the Text component.<\/p>\n<h2 class=\"graf--h2\">Presenting Basic Text(Displaying a Simple Text)<\/h2>\n<p>In this tutorial, we&#8217;ll explore how to showcase plain text using Jetpack Compose.<\/p>\n<p>To display text, we utilize the Text Composable and provide the desired string as its argument. For example,<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60217 size-medium\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/simple_text-300x169.png\" alt=\"\" width=\"300\" height=\"169\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/simple_text-300x169.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/simple_text-1024x576.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/simple_text-768x432.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/simple_text-1536x864.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/simple_text-624x351.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/simple_text.png 1848w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>In this context, <strong>SimpleText<\/strong> represents a Composable function where we utilize the Text component and provide <strong>displayText<\/strong> as its argument.<\/p>\n<p>Now, you can invoke the SimpleText function within the <strong>setContent<\/strong> block of the activity&#8217;s <strong>onCreate<\/strong> method.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60219 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-1024x419.png\" alt=\"\" width=\"625\" height=\"256\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-1024x419.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-300x123.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-768x314.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-1536x629.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-2048x838.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-624x255.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>Here, we are using a <strong>Column<\/strong> that is used to display some content vertically and inside that Column, we are calling the <strong>Simple Text<\/strong> Composable function.<\/p>\n<h2 class=\"graf--h2\">Applying Styles to a Text<\/h2>\n<p>Customizing Text elements with different styles, like adjusting font size and changing colors, is straightforward.<\/p>\n<p>Now, let&#8217;s define a function called <strong>SetTextStyling<\/strong> to implement these style modifications:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-large wp-image-60219\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-1024x419.png\" alt=\"\" width=\"625\" height=\"256\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-1024x419.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-300x123.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-768x314.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-1536x629.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-2048x838.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_styling-624x255.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>In the function described above, <strong>displayText<\/strong> denotes the text content to be displayed, style refers to the desired styling for the Text, and maxLines determines the maximum number of lines permitted for the text. Should the text exceed this limit, ellipsis (&#8230;) will be displayed.<\/p>\n<p>We will call this function by passing these parameters. Let&#8217;s see some of these:<\/p>\n<ul>\n<li><strong>To set font-size:<\/strong><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60222 size-medium\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_size-300x224.png\" alt=\"\" width=\"300\" height=\"224\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_size-300x224.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_size-1024x763.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_size-768x572.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_size-624x465.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_size.png 1208w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<ul>\n<li><strong>To set font-weight, pass text-style as:<\/strong><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60224 size-medium\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_weight-300x159.png\" alt=\"\" width=\"300\" height=\"159\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_weight-300x159.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_weight-1024x544.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_weight-768x408.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_weight-1536x816.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_weight-624x331.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/font_weight.png 1544w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Likewise, you have the ability to adjust font size, text color, font family, underline text, and more.<\/p>\n<h2 class=\"graf--h2\">Collecting user inputs via TextField<\/h2>\n<p>Much like <strong>EditText<\/strong>, Compose provides <strong>TextField<\/strong> and <strong>BaseTextField<\/strong> components for input handling. Notably, <strong>BaseTextField<\/strong> is currently experimental and may change, including potential removal or permanent inclusion. To utilize BaseTextField, the <strong>@ExperimentalFoundationApi<\/strong> annotation must be applied.<\/p>\n<p>The following example showcases a basic implementation of <strong>BaseTextField<\/strong>:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60227 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_field-1024x544.png\" alt=\"\" width=\"625\" height=\"332\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_field-1024x544.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_field-300x159.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_field-768x408.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_field-1536x816.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_field-2048x1089.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/text_field-624x332.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>A BaseTextField is housed within a Surface container within the function described earlier. The function also includes a callback named <strong>onValueChange<\/strong>, which triggers whenever there&#8217;s a change in the input of the <strong>BaseTextField<\/strong>. The updated text is passed as a parameter via this callback.<\/p>\n<p>Here&#8217;s an example demonstrating the use of <strong>BaseTextField<\/strong>. Material Design includes a Composable called <strong>TextField<\/strong> for <strong>EditText<\/strong> functionality. A basic implementation of <strong>TextField<\/strong> is demonstrated below:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60229 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/material_text_field-1024x596.png\" alt=\"\" width=\"625\" height=\"364\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/material_text_field-1024x596.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/material_text_field-300x175.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/material_text_field-768x447.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/material_text_field-1536x894.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/material_text_field-2048x1192.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/material_text_field-624x363.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p><strong>TextField<\/strong> functions similarly to <strong>BaseTextField<\/strong>. One additional thing you have here in <strong>TextField<\/strong> is a label. When a <strong>TextField<\/strong> is empty, a label is the text that appears within the <strong>TextField<\/strong>.<\/p>\n<p>By providing it with different arguments, we are able to modify both this <strong>BaseTextField<\/strong> and the <strong>TextField<\/strong>. For instance,<\/p>\n<ul>\n<li><strong>To show only numerical keyboard:<\/strong><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60242 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-1024x475.png\" alt=\"\" width=\"625\" height=\"290\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-1024x475.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-300x139.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-768x356.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-1536x713.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-2048x950.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-624x290.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<ul>\n<li><strong>To add a placeholder in TextField(will be displayed when TextField is empty and focused)<\/strong><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60243 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-1-1024x472.png\" alt=\"\" width=\"625\" height=\"288\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-1-1024x472.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-1-300x138.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-1-768x354.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-1-1536x708.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-1-624x287.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-1.png 1780w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>In a similar manner, we may specify <strong>errorColor<\/strong>, <strong>backgroundColor<\/strong>, <strong>intractionState<\/strong>, <strong>activeColor<\/strong>, <strong>inactiveColor<\/strong>, <strong>add icons<\/strong>, and display error messages in <strong>TextFiled<\/strong>.<\/p>\n<p>You may experiment with them and view the results directly in Android Studio. You heard correctly. Any UI element can be previewed directly within Android Studio.\u00a0 Let&#8217;s examine how.<\/p>\n<h2 class=\"graf--h2\">Preview in Android Studio<\/h2>\n<p>One fantastic feature of Android Studio is the ability to preview your UI components dynamically within the studio. Thus, you can easily preview UI components in Android Studio by creating a Composable function and using the @Preview annotation whenever you wish to test them.<\/p>\n<p>Here&#8217;s an illustration of the same:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60244 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-2-1024x662.png\" alt=\"\" width=\"625\" height=\"404\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-2-1024x662.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-2-300x194.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-2-768x496.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-2-1536x993.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-2-2048x1324.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-2-624x403.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>You may now examine a preview of the aforementioned Composable function in the preview tab on the right side of the Studio.<\/p>\n<p>You may use as many alternative width and height previews as you like. The Android Studio will take you to the line where that UI is built if you click on any of the UI elements in the preview.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60246 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-2024-02-05-165431-1-1024x511.png\" alt=\"\" width=\"625\" height=\"312\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-2024-02-05-165431-1-1024x511.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-2024-02-05-165431-1-300x150.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-2024-02-05-165431-1-768x383.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-2024-02-05-165431-1-624x312.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-2024-02-05-165431-1.png 1394w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p><strong>NOTE: A Preview Composable function cannot have any parameters passed to it.<\/strong><\/p>\n<h2 class=\"graf--h2\">Column<\/h2>\n<p>A <strong>column<\/strong> is a modular layout that arranges all of its children in a vertical row after one another. With its vertical orientation, it is comparable to <strong>LinearLayout<\/strong>.<\/p>\n<p>An illustration of a column is as follows:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60247 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-3-1024x481.png\" alt=\"\" width=\"625\" height=\"294\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-3-1024x481.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-3-300x141.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-3-768x361.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-3-1536x721.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-3-2048x962.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-3-624x293.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<h2 class=\"graf--h2\">Box<\/h2>\n<p>A composable pattern called a &#8220;<strong>Box<\/strong>&#8221; is utilized to arrange kids in relation to its edges. At first, Stack was utilized rather than Box. Now, however, Box has been introduced and Stack is deprecated.<\/p>\n<p>The children are housed inside the parent, as the term implies. The kids inside a box are drawn in the designated sequence, and based on alignment, if the kids are smaller than the parent, they will automatically be inside the box.<\/p>\n<p>Here&#8217;s an illustration of a Box:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60248 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-5-1024x579.png\" alt=\"\" width=\"625\" height=\"353\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-5-1024x579.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-5-300x170.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-5-768x434.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-5-1536x869.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-5-2048x1159.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-5-624x353.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<h2 class=\"graf--h2\">Button<\/h2>\n<p>When a <strong>button<\/strong> is clicked, it is intended to carry out a specific function.<\/p>\n<p>An illustration of a basic button is as follows:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60249 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-6-1024x483.png\" alt=\"\" width=\"625\" height=\"295\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-6-1024x483.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-6-300x142.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-6-768x362.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-6-1536x725.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-6-2048x966.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-6-624x294.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>In this case, text is applied to the button using Text, and the button&#8217;s click event is heard using the <strong>onClick<\/strong> callback.<\/p>\n<p>You can fully configure a Button by supplying it different parameters. Among them are:<\/p>\n<ul>\n<li><strong>Make rounded corners Button:<\/strong><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60250 size-medium\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-7-300x156.png\" alt=\"\" width=\"300\" height=\"156\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-7-300x156.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-7-1024x534.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-7-768x400.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-7-1536x800.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-7-624x325.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-7.png 1712w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<ul>\n<li><strong>Make a Button with borders:<\/strong><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60251 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-8-1024x316.png\" alt=\"\" width=\"625\" height=\"193\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-8-1024x316.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-8-300x93.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-8-768x237.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-8-1536x474.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-8-2048x632.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-8-624x192.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>Similar to this, you can add an icon, change the color of a button, deactivate a button, outline a button, create an <strong>IconButton<\/strong>, create a <strong>FAB<\/strong>, and so on.<\/p>\n<h2 class=\"graf--h2\"><b class=\"graf--bold\">Card<\/b><\/h2>\n<p>A Card is a layout composable that is used to make a <strong>CardView<\/strong>. The following is an example of the same:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60253 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-10-1024x785.png\" alt=\"\" width=\"625\" height=\"479\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-10-1024x785.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-10-300x230.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-10-768x589.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-10-1536x1178.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-10-2048x1571.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-10-624x479.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<h2 class=\"graf--h2\">Image<\/h2>\n<p class=\"graf--p\">To display an image, we can use <strong>Image<\/strong> composable.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60254 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-11-1024x552.png\" alt=\"\" width=\"625\" height=\"337\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-11-1024x552.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-11-300x162.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-11-768x414.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-11-1536x828.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-11-2048x1104.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-11-624x336.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p class=\"graf--p\">You can also make a rounded corner image by using the below code:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60255 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-12-1024x350.png\" alt=\"\" width=\"625\" height=\"214\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-12-1024x350.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-12-300x103.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-12-768x263.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-12-1536x525.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-12-2048x700.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-12-624x213.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<h2 class=\"graf--h2\">Alert Dialog<\/h2>\n<p>As the name implies, <strong>AlertDialog<\/strong> is used to present the user with some vital messages in the form of a dialog that may include actions.<\/p>\n<p>An AlertDialog has a title, text, confirm button, and dismiss button.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60256 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-13-840x1024.png\" alt=\"\" width=\"625\" height=\"762\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-13-840x1024.png 840w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-13-246x300.png 246w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-13-768x937.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-13-1260x1536.png 1260w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-13-1679x2048.png 1679w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-13-624x761.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<h2 class=\"graf--h2\">Material BottomNavigation<\/h2>\n<p><strong>BottomNavigation<\/strong> is a feature that places some of the app&#8217;s most crucial activities at the bottom of the screen for user convenience. We must utilize the <strong>BottomNavigationItem<\/strong> composable in order to add an item to a BottomNavigation.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60257 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-14-1024x835.png\" alt=\"\" width=\"625\" height=\"510\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-14-1024x835.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-14-300x245.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-14-768x626.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-14-1536x1252.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-14-2048x1670.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-14-624x509.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>Use <strong>alwaysShowLabels = false<\/strong> in <strong>BottomNavigationItem<\/strong> to use <strong>BottomNavigation<\/strong> without labels.<\/p>\n<h2 class=\"graf--h2\">Material ProgressBar<\/h2>\n<p>A ProgressBar is utilized to display the progress that is being made in the app at the moment. For instance, loading data from the server or downloading progress. Either a linear or circular progress bar can be created. An illustration of a circular progress bar is as follows:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60258 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-15-1024x605.png\" alt=\"\" width=\"625\" height=\"369\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-15-1024x605.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-15-300x177.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-15-768x454.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-15-1536x908.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-15-624x369.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-15.png 2016w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>In a similar vein, the <strong>LinearProgressIndicator<\/strong> is likewise applicable.<\/p>\n<h2 class=\"graf--h2\">Material Checkbox<\/h2>\n<p>A <strong>checkbox<\/strong> is used when we have 2 options and the user can either select or unselect the options.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60259 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-16-1024x536.png\" alt=\"\" width=\"625\" height=\"327\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-16-1024x536.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-16-300x157.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-16-768x402.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-16-1536x803.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-16-2048x1071.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-16-624x326.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<h2 class=\"graf--h2\">Material Snackbar<\/h2>\n<p><strong>Snackbars<\/strong> are used to display information at the bottom of the screen, covering all UI components.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60260 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-18-1024x674.png\" alt=\"\" width=\"625\" height=\"411\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-18-1024x674.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-18-300x198.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-18-768x506.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-18-1536x1012.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-18-2048x1349.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/carbon-18-624x411.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>This concludes the tutorial. You may use Jetpack Compose to try out a lot more examples.<\/p>\n<p class=\"graf--p\">Keep <strong>Learning<\/strong>! Keep <strong>Coding<\/strong>!<\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Join us in exploring Jetpack Compose\u2014a cutting-edge toolkit that simplifies the process of crafting native user interfaces. This tutorial offers a comprehensive guide on utilizing various Jetpack Compose features such as Text, TextField, Preview, Column, Row, Button, Card, AlertDialog, and MaterialDesign elements. Let&#8217;s kick things off by creating a Jetpack Compose Project and delve into [&hellip;]<\/p>\n","protected":false},"author":1493,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":193},"categories":[518,1772],"tags":[5626,5639,5638,5637],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/60211"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1493"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=60211"}],"version-history":[{"count":7,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/60211\/revisions"}],"predecessor-version":[{"id":60758,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/60211\/revisions\/60758"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=60211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=60211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=60211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}