Tugas 5 - Studi Kasus - Membuat Halaman Login
Code Untuk Tugas 5 Membuat Halaman Login
MainActivity.kt
Pada MainActivity kita hanya mempassing LofinScreen() dari file LoginScreen.kt. jadi code pada MainActivity.kt akan seperti dibawah ini
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.mylogin | |
import android.os.Bundle | |
import androidx.activity.ComponentActivity | |
import androidx.activity.compose.setContent | |
import androidx.compose.foundation.layout.fillMaxSize | |
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.tooling.preview.Preview | |
import com.example.mylogin.ui.theme.MyLoginTheme | |
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
LoginScreen() | |
} | |
} | |
} | |
LoginScreen.kt
Semua code halaman login akan di tulis pada LoginScreen,kt, jika membutuhkan gambar maka gambar akan di masukkan pada file res > drawable. jadi code dari LoginScreen.kt ajan menjadi seperti dibawah ini
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.mylogin | |
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.material3.TextButton | |
import androidx.compose.material3.TextField | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.mutableStateOf | |
import androidx.compose.runtime.remember | |
import androidx.compose.runtime.setValue | |
import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.res.painterResource | |
import androidx.compose.ui.text.font.Font | |
import androidx.compose.ui.text.font.FontWeight | |
import androidx.compose.ui.text.input.PasswordVisualTransformation | |
import androidx.compose.ui.tooling.preview.Preview | |
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.logo), contentDescription = "Login Image", | |
modifier = Modifier.size(300.dp)) | |
Text(text = "WELCOME", fontSize = 28.sp, fontWeight = FontWeight.Bold) | |
Spacer(modifier = Modifier.height(4.dp)) | |
Text(text = "Login to Pokedex") | |
Spacer(modifier = Modifier.height(16.dp)) | |
OutlinedTextField(value = email, onValueChange = {email = it}, label = { | |
Text(text = "Email") | |
}) | |
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 : $email")}) { | |
Text(text = "LOGIN") | |
} | |
Spacer(modifier = Modifier.height(16.dp)) | |
Text(text = "Forgot Password ?", modifier = Modifier.clickable { | |
}) | |
Spacer(modifier = Modifier.height(32.dp)) | |
Text(text = "Or Sign in With") | |
Spacer(modifier = Modifier.height(16.dp)) | |
Row (modifier = Modifier | |
.fillMaxWidth() | |
.padding(40.dp), | |
horizontalArrangement = Arrangement.SpaceEvenly | |
){ | |
Image(painter = painterResource(id = R.drawable.login2), | |
contentDescription = "login 1", | |
modifier = Modifier | |
.size(60.dp) | |
.clickable { | |
} | |
) | |
Image(painter = painterResource(id = R.drawable.login4), | |
contentDescription = "login 2", | |
modifier = Modifier | |
.size(60.dp) | |
.clickable { | |
} | |
) | |
Image(painter = painterResource(id = R.drawable.login5), | |
contentDescription = "login 3", | |
modifier = Modifier | |
.size(60.dp) | |
.clickable { | |
} | |
) | |
} | |
} | |
} |
Komentar
Posting Komentar