Tugas 5 PPB I
Tugas 5 - Membuat Halaman Login Sederhana
Nama: Muhammad Ghani Taufiqurrahman Atmaja
NRP : 5025201110
Kelas: PPB - I
Dalam tugas ini, saya membuat halaman login sederhana menggunakan Kotlin dan dibantu dengan Jetpack Compose. Berikut adalah kode program dan hasil pengerjaannya.
Source Code: Repo
Code:
Kode pada Login.kt :
package com.example.tugas5ppb
import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.*
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@Composable
fun LoginScreen() {
var email by remember {
mutableStateOf("")
}
var password by remember {
mutableStateOf("")
}
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
){
Image(painter = painterResource(id = R.drawable.bg), contentDescription = "Login Image",
modifier = Modifier.size(200.dp))
Text(text = "Welcome Back", fontSize = 28.sp, fontWeight = FontWeight.Bold)
Spacer(modifier = Modifier.height(4.dp))
Text(text = "Login to your account")
Spacer(modifier = Modifier.height(16.dp))
OutlinedTextField(value = email , onValueChange = {
email = it }, label = {
Text(text = "Email address")
})
Spacer(modifier = Modifier.height(16.dp))
OutlinedTextField(value = password , onValueChange = {
password = it }, label = {
Text(text = "Password")
}, visualTransformation = PasswordVisualTransformation())
Spacer(modifier = Modifier.height(16.dp))
Button(onClick = {
Log.i("Credential", "Email : $email Password : $password")
}) {
Text(text = "Login")
}
Spacer(modifier = Modifier.height(32.dp))
Text(text = "Forgot Password?", modifier = Modifier.clickable { })
Spacer(modifier = Modifier.height(32.dp))
Text(text = "Or sign in with")
Row (
modifier = Modifier.fillMaxWidth().padding(40.dp),
horizontalArrangement = Arrangement.SpaceEvenly
){
Image(painter = painterResource(id = R.drawable.facebook),
contentDescription = "Facebook",
modifier = Modifier
.size(60.dp)
.clickable {
})
Image(painter = painterResource(id = R.drawable.google), contentDescription = "Google",
modifier = Modifier
.size(60.dp)
.clickable {
})
Image(painter = painterResource(id = R.drawable.twitter),
contentDescription = "Twitter",
modifier = Modifier
.size(60.dp)
.clickable {
})
}
}
}
Kode pada MainActivity.kt :
package com.example.tugas5ppb
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
LoginScreen()
}
}
}
@Preview(showBackground = true, showSystemUi = true, name = "My Preview" )
@Composable
fun LoginScreenPreview(){
LoginScreen()
}
Comments
Post a Comment