Skip to main content

Posts

jetpack compose - Button rounded corners

Compose Button Rounded Corners The Button is a primary component of the android jetpack compose library. A Button is used to perform an action. The widget has an onClick event. We can add a Text composable or any other composable as child elements of the Button. Commonly used Text widget or a Text widget with an icon as Button elements to describe the action to perform on Button click event. This android jetpack compose tutorial will demonstrate how we can display a rounded corners-shaped Button widget on the app screen. And how we can change the corner radius size or percentage for a Button widget. We know the Button widget constructor has an argument named ‘shape’, this shape argument accepts a ‘Shape’ type of value. The default value for the ‘shape’ parameter is ‘MaterialTheme.shapes.small’. We can set or change the Button shape using this shape argument. Such as, when we set the value of the ‘shape’ argument to ‘CircleShape’ then it displays a circular-shaped Button widget...

jetpack compose - Button color

MainActivity.kt package com.cfsuman.jetpackcompose import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.activity.compose.setContent import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.Column import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { MainContent() } } @Composable fun MainContent(){ Column( Modifier .background(Color(0xFFEDEAE0)) .fillMaxSize() .padding(32.dp), verticalArrangement = Arrangement.spacedBy...

jetpack compose - Button with icon

Compose Button With Icon & Text The Button is a primary widget of an android application, and for any software development SDK. Without a Button widget, we can’t build software or mobile application. The Button provides a click functionality. Android jetpack compose library provides a few built-in widgets to create many types of Buttons such as Button, TextButton, OutlinedButton, FloatingActionButton, IconButton, etc. Different types of Button widgets allow us to render the different types of Button in the mobile user interface an example, IconButton can render an Icon inside IconButon with click action, and TextButton simply shows a Text object inside TextButton itself. OutlinedButton draws a border around the text button, etc. The Button widget shows a Text object with a background color and elevation. But in some situations, android developers have to render a Button widget with both Text and an Icon. This android development tutorial will show you how we can show an Ic...

jetpack compose - TextButton

MainActivity.kt package com.cfsuman.jetpackcompose import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.activity.compose.setContent import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.Column import androidx.compose.material.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Share import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { MainContent() } } @Composable fun MainContent(){ Column( Modifier .background(Color(0xFFEDEAE0)) .fill...

jetpack compose - Outlined Button

MainActivity.kt package com.cfsuman.jetpackcompose import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.activity.compose.setContent import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.Column import androidx.compose.material.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Favorite import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { MainContent() } } @Composable fun MainContent(){ Column( Modifier .background(Color(0xFFEDEAE0)) .f...

Jetpack Compose: Understanding the Weight modifier

Jetpack Compose is a modern toolkit introduced by Google for building native Android UI with less boilerplate code. It offers a new way to construct interfaces using a declarative approach, which is more intuitive and efficient compared to the traditional XML-based layouts. One of the powerful features of Jetpack Compose is its layout system, where modifiers play a significant role in controlling how elements are displayed on the screen. In this article, we'll explore the use of the weight modifier, which is essential for distributing space among composables within a container like a Column or Row . In this particular example, we focus on how the weight modifier can be used to proportionally allocate space to different UI components. Understanding how to properly leverage weight is key to creating flexible and responsive designs in Jetpack Compose. This guide will break down the example and explain each part to help you understand how to apply the weight modifier effectively. ...

Jetpack Compose: Panning zooming rotating

Introduction In the world of Android development, creating interactive and responsive user interfaces has always been a challenge, especially when it comes to handling gestures like panning, zooming, and rotating. Jetpack Compose, Android's modern toolkit for building native UI, offers a declarative approach that simplifies implementing such interactions. Leveraging Jetpack Compose’s capabilities, developers can create seamless and intuitive interfaces that respond to user gestures without writing boilerplate code. This article walks you through an example of how to implement panning, zooming, and rotating gestures on an image using Jetpack Compose. We'll explore the key components and techniques used to make a simple yet effective interactive UI. This guide is designed to help you understand how to integrate gesture-based interactions in your apps, enhancing the user experience while keeping your code clean and efficient. Breaking Down the Code The application starts with a ty...