commit 90ea628f8d2d583c4ecc3871d1169fa8c77024a1 Author: 202310715277 LALU MUHAMMAD ANGGANA SUBHAN <202310715277@mhs.ubharajaya.ac.id> Date: Wed Oct 29 09:40:43 2025 +0700 Upload files to "/" tugas 2 android studio diff --git a/MainActivity.kt b/MainActivity.kt new file mode 100644 index 0000000..ee8833d --- /dev/null +++ b/MainActivity.kt @@ -0,0 +1,70 @@ +package com.example.myapplication + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.tooling.preview.Preview +import com.example.myapplication.ui.theme.MyApplicationTheme + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContent { + MyApplicationTheme { + Scaffold( + modifier = Modifier.fillMaxSize() + ) { innerPadding -> // <-- gunakan innerPadding + // letakkan Box/Surface agar background dan padding saling berurutan + Box( + modifier = Modifier + .fillMaxSize() + .background(Color(0xFF0D47A1)) // contoh biru gelap; bisa pake Color.Blue juga + .padding(innerPadding) // <-- pakai innerPadding di sini + ) { + Greeting( + name = "Android", + modifier = Modifier // kalau mau beri margin/padding lagi, tambahkan di sini + ) + } + } + } + } + } +} + +@Composable +fun Greeting(name: String, modifier: Modifier = Modifier) { + Text( + text = "Hello $name!", + color = Color.White, + modifier = modifier + ) +} + +@Preview(showBackground = true) +@Composable +fun GreetingPreview() { + MyApplicationTheme { + Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> + Box( + modifier = Modifier + .fillMaxSize() + .background(Color(0xFF0D47A1)) + .padding(innerPadding) + ) { + Greeting("Lalu Angga") + } + } + } +}