Skip to main content

Posts

Showing posts with the label Compose Button

jetpack compose - Button elevation

Compose Button Elevation The Button is a primary component of an android application. Android application developers can’t imagine an application without a Button widget. In the jetpack compose library there are several types of Button widgets such as Button, TextButton, FloatingActionButton, OutlinedButton, IconButton, etc, Android application developers used them in their app user interface for various requirements. Such as an IconButton shows an Icon inside it with a clickable functionality. TextButton displays a clickable simple Text object. By default, TextButton has no elevation. The Button widget has an elevation but we can change its elevation value. This android application development tutorial will demonstrate to us how we can set or change a Button widget elevation in jetpack compose. In this example, we will set or change Button, TextButton, and OutlinedButton’s elevation size/value. We also change the TextButton’s different states elevations such as default eleva...

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: How to use Button

Jetpack Compose - Button Example Breakdown This code demonstrates how to create a simple button using Jetpack Compose in an Android application. It allows users to click the button and displays a toast message indicating the number of times it has been clicked. Here's a breakdown of the code: Imports: The code starts by importing necessary libraries, including androidx.compose.material for building the button and androidx.activity.compose.setContent to set the composable content for the activity. MainActivity: This is the main activity class that extends AppCompatActivity . onCreate: This lifecycle method sets the content of the activity using setContent which takes a composable function ( MainContent ) as an argument. MainContent: This composable function defines the UI structure of the app. counter variable: It initializes a variable counter to track the number of clicks. Button: This composable creates a button with several properties: onClick : This defines t...