Program "Hello Pak Fajar" dengan Android Studio
Pada tugas ke-2 kuliah Pemrograman Perangkat Bergerak (PPB), saya membuat program "Hello Pak Fajar" dengan foto background bertemakan pendidikan.
MainActivity.kt
This file contains 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.helloworld | |
import android.os.Bundle | |
import androidx.activity.ComponentActivity | |
import androidx.activity.compose.setContent | |
import androidx.compose.foundation.Image | |
import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.material.MaterialTheme | |
import androidx.compose.material.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.res.painterResource | |
import androidx.compose.ui.res.stringResource | |
import androidx.compose.ui.tooling.preview.Preview | |
import androidx.compose.ui.unit.dp | |
import com.bangkit.hellowolrd.R | |
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
Box( | |
modifier = Modifier.fillMaxSize(), | |
contentAlignment = Alignment.Center | |
) { | |
BackgroundImage() | |
Greeting() | |
} | |
} | |
} | |
} | |
@Composable | |
fun BackgroundImage() { | |
val image = painterResource(id = R.drawable.background) | |
Image( | |
painter = image, | |
contentDescription = null, | |
modifier = Modifier.fillMaxSize() | |
) | |
} | |
@Composable | |
fun Greeting() { | |
Text( | |
text = stringResource(id = R.string.greeting), | |
color = Color.Black, | |
style = MaterialTheme.typography.h4, | |
modifier = Modifier.padding(16.dp) | |
) | |
} | |
@Preview(showBackground = true) | |
@Composable | |
fun DefaultPreview() { | |
Greeting() | |
} |
This file contains 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
<resources> | |
<string name="greeting">Hello Pak Fajar!</string> | |
</resources> |
Komentar
Posting Komentar