Advertisement
Samuel_Berkat_Hulu

TUGAS 3 PPB F

Mar 26th, 2024
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. package com.example.tugas3ppbf
  2.  
  3. import android.os.Bundle
  4. import androidx.activity.ComponentActivity
  5. import androidx.activity.compose.setContent
  6. import androidx.compose.foundation.layout.Arrangement
  7. import androidx.compose.foundation.layout.Column
  8. import androidx.compose.foundation.layout.fillMaxSize
  9. import androidx.compose.foundation.layout.padding
  10. import androidx.compose.material3.MaterialTheme
  11. import androidx.compose.material3.Surface
  12. import androidx.compose.material3.Text
  13. import androidx.compose.runtime.Composable
  14. import androidx.compose.ui.Alignment
  15. import androidx.compose.ui.Modifier
  16. import androidx.compose.ui.text.style.TextAlign
  17. import androidx.compose.ui.tooling.preview.Preview
  18. import androidx.compose.ui.unit.dp
  19. import androidx.compose.ui.unit.sp
  20. import com.example.tugas3ppbf.ui.theme.HappyBirthdayTheme
  21.  
  22. class MainActivity : ComponentActivity() {
  23.     override fun onCreate(savedInstanceState: Bundle?) {
  24.         super.onCreate(savedInstanceState)
  25.         setContent {
  26.             HappyBirthdayTheme {
  27.                 // A surface container using the 'background' color from the theme
  28.                 Surface(
  29.                     modifier = Modifier.fillMaxSize(),
  30.                     color = MaterialTheme.colorScheme.background
  31.                 ) {
  32.                     GreetingText(
  33.                         message = "Happy Birthday BRO!",
  34.                         from = "From Samuel",
  35.                         modifier = Modifier.padding(8.dp)
  36.                     )
  37.                 }
  38.             }
  39.         }
  40.     }
  41. }
  42.  
  43. @Composable
  44. fun GreetingText(message: String, from: String, modifier: Modifier) {
  45.     Column(
  46.         verticalArrangement = Arrangement.Center,
  47.         modifier = modifier
  48.     ) {
  49.         Text(
  50.             text = message,
  51.             fontSize = 100.sp,
  52.             lineHeight = 116.sp,
  53.             textAlign = TextAlign.Center
  54.         )
  55.  
  56.         Text(
  57.             text = from,
  58.             fontSize = 36.sp,
  59.             modifier = Modifier
  60.                 .padding(16.dp)
  61.                 .align(alignment = Alignment.End)
  62.         )
  63.     }
  64. }
  65.  
  66. @Preview(showBackground = true)
  67. @Composable
  68. fun BirthdayCardPreview() {
  69.     HappyBirthdayTheme {
  70.         GreetingText(message = "Happy Birthday BRO!", from = "From Samuel", modifier = Modifier)
  71.     }
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement