71 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Kotlin
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Kotlin
		
	
	
	
	
	
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")
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |