๋ชฉ์ฐจ
6. ๋ฐฐ๊ฒฝ ์์ ๋ณ๊ฒฝ
import ์ ์ํ๋ฒณ ์์ผ๋ก ํ๋ ๊ฒ ์ข๋ค.
help - find action - Optimize Imports ํด๋ฆญ
@Composable
fun Greeting(name: String) {
Surface(color = Color.Magenta) {
Text(text = "Hello my name is $name!")
}
}
7. ํจ๋ฉ ์ถ๊ฐ
ํ ์คํธ ์ฃผ์์ ๊ณต๋ฐฑ(ํจ๋ฉ)์ ์ถ๊ฐํด๋ณด์
@Composable
fun Greeting(name: String) {
Surface(color = Color.Magenta) {
Text(text = "Hi, my name is $name!", modifier = Modifier.padding(24.dp))
}
}
Modifier๋ ์ปดํฌ์ ๋ธ์ ๊ฐํํ๊ฑฐ๋ ์ฅ์ํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
์ฌ์ฉ ํ ์ ์๋ ํ๊ฐ์ง ์์ ์๋ padding ์์ ์์ด๋ฉฐ ์ด๋ ์์ ์ฃผ์์ ๊ณต๋ฐฑ์ ์ ์ฉํฉ๋๋ค.
์ฌ๊ธฐ์๋ ํ ์คํธ ์ฃผ์์ ๊ณต๋ฐฑ์ ์ถ๊ฐํฉ๋๋ค.
@Composable
fun Greeting(name: String) {
Surface(color = Color.Magenta) {
Text(text = "Hello my name is $name!", Modifier.padding(24.dp))
}
}
์๋ฃจ์ ์ฝ๋
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.myapplication.ui.theme.GreetingCardTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
GreetingCardTheme {
// A surface container that uses the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
Greeting("Android")
}
}
}
}
}
@Composable
fun Greeting(name: String) {
Surface(color = Color.Magenta) {
Text(text = "Hi, my name is $name!", modifier = Modifier.padding(24.dp))
}
}
@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
GreetingCardTheme {
Greeting("Meghan")
}
}
์์ฝ
๊ตฌ์ฑ๊ฐ๋ฅํ ํจ์๋ ์ผ๋ฐ ํจ์์ ๋น์ทํ์ง๋ง ๋ช ๊ฐ์ง ์ฐจ์ด๊ฐ ์๋ค.
ํจ์ ์ด๋ฆ์ ๋๋ฌธ์๋ก ํ๊ธฐ๋๋ฉฐ ํจ์ ์์ @Composable ์ฃผ์์ ์ถ๊ฐํ๊ณ
@Composable ํจ์๋ ์๋ฌด๊ฒ๋ ๋ฐํํ ์ ์๋ค.
Modifier์ ์ปดํฌ์ ๋ธ์ ๊ฐํํ๊ฑฐ๋ ์ฅ์ํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
'2023 ์๋๋ก์ด๋ > ์๋๋ก์ด๋ ์คํฐ๋' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Android ์ฑ์ ์ด๋ฏธ์ง ์ถ๊ฐ ~5 (0) | 2022.11.16 |
---|---|
๊ธฐ๋ณธ ๋ ์ด์์ ๋ง๋ค๊ธฐ (0) | 2022.11.16 |
์ฒซ ๋ฒ์งธ Android ์ฑ ๋ง๋ค๊ธฐ 5 (0) | 2022.11.15 |
์ฐ์ต๋ฌธ์ (0) | 2022.11.15 |
์๋๋ก์ด๋ ์คํฐ๋ 1์ผ์ฐจ ๊ณผ์ unit1 (0) | 2022.11.15 |