Jetpack Compose 是 用于构建原生UI界面的新款Android工具包。
声明式UI
?
package com.tiger.compose0117
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.tiger.compose0117.ui.theme.Compose0117Theme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
// Compose0117Theme {
// // A surface container using the 'background' color from the theme
// Surface(
// modifier = Modifier.fillMaxSize(),
// color = MaterialTheme.colorScheme.background
// ) {
// Greeting("Android")
// }
// }
Greeting(name = "Compose Colin")
}
}
}
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}
//
//@Preview(showBackground = true)
//@Composable
//fun GreetingPreview() {
// Compose0117Theme {
// Greeting("Android")
// }
//}
?