Tugas 2 Pemrograman Perangkat Bergerak

Nama: Amanda Salwa Salsabila

NRP: 5025201172

Tugas 2 PPB


Latihan Jetpack Compose

Berikut merupakan source code dari halaman antarmuka pengguna

package com.example.latihan1ppb
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.Alignment
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.latihan1ppb.ui.theme.Latihan1PPBTheme
import com.example.latihan1ppb.ui.theme.Pink20
import com.example.latihan1ppb.ui.theme.Pink80
import com.example.latihan1ppb.ui.theme.Pink40
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Latihan1PPBTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
Greeting("Sanrio Land", "Amanda Salwa Salsabila", "5025201172", "2002 November 25","My Melody")
}
}
}
}
}
@Composable
fun ShowImage() {
Image(
painter = painterResource(id = R.drawable.melo_icon),
contentDescription = "Icon of My Melody",
modifier = Modifier
.width(150.dp)
.height(150.dp)
)
}
@Composable
fun Greeting(title: String, name: String, nrp: String, dob: String, chara: String, modifier: Modifier = Modifier) {
Column(
modifier = Modifier.fillMaxSize().background(Pink80),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center)
{
Text(
text = "Welcome to $title",
fontSize = 32.sp,
fontStyle = FontStyle.Italic
)
ShowImage()
Text(
text = "Member Name: $name"
)
Text(
text = "Member Number: $nrp"
)
Text(
text = "Date of Birth: $dob"
)
Text(
text = "Chosen Character Theme: $chara"
)
}
}
@Preview(showBackground = true, showSystemUi = true)
@Composable
fun GreetingPreview() {
Latihan1PPBTheme {
Greeting("Sanrio Land", "Amanda Salwa Salsabila", "5025201172", "2002 November 25","My Melody")
}
}
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