「Android/kotlin/JetpackComponent」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==初期のテンプレ== MainActivety.kt <pre> package com.example.myapplication import android.os.Bundle import androidx.activity.ComponentActivity import androidx.act...」) |
(→初期のテンプレ) |
||
| 行1: | 行1: | ||
| − | == | + | ==プロジェクト作成時のJetpackComponentの初期のテンプレ== |
MainActivety.kt | MainActivety.kt | ||
<pre> | <pre> | ||
2024年9月12日 (木) 01:16時点における最新版
プロジェクト作成時のJetpackComponentの初期のテンプレ
MainActivety.kt
package com.example.myapplication
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.myapplication.ui.theme.AndroidProjectJavaTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AndroidProjectJavaTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting("Android")
}
}
}
}
}
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
AndroidProjectJavaTheme {
Greeting("Android")
}
}
