我正在 Android 开发者网站上学习 Android Basics with Compose 课程。在过去十天左右的时间里,我遇到了一个障碍:每当我尝试打开分割设计视图(或常规设计视图)时,都不会显示任何内容。我正在开发(非常简单)“生日卡”项目,该项目应该显示“生日快乐,梅根”,并带有填充和背景,但它甚至不会显示。
大约两周前就可以工作了。
这是我迄今为止尝试过的:
这是我正在使用的:
该怎么办?我想继续学习 Android 基础知识与 Compose 课程,并希望在大约一个月内开始 Coursera 课程,并希望做好准备。与此同时,我一直在 IntelliJ 上进行为期 13 周的 Kotlin 代码实验室,以便更好地使用纯 Kotlin。但我需要尽快进入 Compose。
提前致谢。
和 2)我想运行的简单代码:
package com.example.happybirthday
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.happybirthday.ui.theme.HappyBirthdayTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
HappyBirthdayTheme {
// 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() {
HappyBirthdayTheme {
Greeting("Android")
}
}
我遇到了同样的问题,很愚蠢,我意识到我被缩小了太多,以至于文本在我的预览窗格中不可见。您尝试过使用缩放控件吗?