package com.example.tipamountapp import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.material3.Button import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TextField import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.tooling.preview.Preview import com.example.tipamountapp.ui.theme.TipAmountAppTheme class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { calculateTipAmount() } } @Composable fun calculateTipAmount() { val amnt = 0 // val newText="" var text by remember { mutableStateOf(TextFieldValue("")) } Column( modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { TextField( value = text, onValueChange = { text = it }, placeholder = { Text(text = "please enter your bill") } ) Button(onClick = { val bill = Integer.parseInt(text.toString()) val res = 0.05 * (bill) // Text(text = "your tip amount is ${res}") print(res) }) { Text(text = "Press to Calculate") } } } //fun print(res:Double){ // Text(text = "your tip is :${res}") // //} }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter