Tugas 3 Pemrograman Perangkat Bergerak

Nama: Amanda Salwa Salsabila

NRP: 5025201172

Tugas 3 PPB


Latihan Aplikasi Happy Birthday

Berikut merupakan source code dari halaman antarmuka pengguna

package com.example.latihan2ppb
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
//import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.latihan2ppb.ui.theme.Latihan2PPBTheme
import com.example.latihan2ppb.ui.theme.Pink40
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Latihan2PPBTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting("Amanda", reciever ="Sam")
}
}
}
}
}
@Composable
fun Greeting(sender: String, reciever: String, modifier: Modifier = Modifier) {
Column(
modifier = Modifier
.fillMaxSize()
.background(Pink40),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center)
{
Text(
text = "Happy",
fontSize = 60.sp,
fontWeight = FontWeight.Bold,
color = Color.Black
)
Text(
text = "Birthday $reciever",
fontSize = 60.sp,
fontWeight = FontWeight.Bold,
color = Color.Black
)
Spacer(modifier = Modifier.size(10.dp))
Text(
text = "From $sender",
fontSize = 16.sp,
fontStyle = FontStyle.Italic,
color = Color.Black
)
}
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
Latihan2PPBTheme {
Greeting("Amanda", reciever ="Sam")
}
}
view raw MainActivity.kt hosted with ❤ by GitHub


Berikut merupakan tampilan dari halaman antarmuka pengguna










Comments

Popular posts from this blog

ETS Pemrograman Perangkat Bergerak