import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Button(onClick = {
Toast.makeText(this, "Button clicked!", Toast.LENGTH_SHORT).show()
}) {
Text(text = "Click Me")
}
}
}
}
}We use a Box to center the button on the screen by setting contentAlignment = Alignment.Center. Inside the Box, we add a Button composable with the text 'Click Me'. The onClick lambda shows a Toast message 'Button clicked!' using Toast.makeText. This gives immediate feedback when the user taps the button.