我的设计视图和任何 Android 虚拟设备都不会显示任何内容

问题描述 投票:0回答:1

我正在 Android 开发者网站上学习 Android Basics with Compose 课程。在过去十天左右的时间里,我遇到了一个障碍:每当我尝试打开分割设计视图(或常规设计视图)时,都不会显示任何内容。我正在开发(非常简单)“生日卡”项目,该项目应该显示“生日快乐,梅根”,并带有填充和背景,但它甚至不会显示。

大约两周前就可以工作了。

这是我迄今为止尝试过的:

  • 重新安装Android Studio(我已经这样做了两次)。
  • 不使用我想要保存 Android 开发内容的首选目录,而只是使用默认文件夹来保存。
  • 删除之前的android studio作业和“实验”(只有两三个),希望消除一些其他代码对当前代码的影响。

这是我正在使用的:

  • 运行 Windows 11 的 HP 笔记本电脑
  • 8 GB RAM,可升级至 32 GB
  • Android Studio 鬣蜥 | 2023.2.1 补丁 1

该怎么办?我想继续学习 Android 基础知识与 Compose 课程,并且希望在大约一个月内开始 Coursera 课程,并希望做好准备。与此同时,我一直在 IntelliJ 上进行为期 13 周的 Kotlin 代码实验室,以便更好地使用纯 Kotlin。但我需要尽快进入 Compose。

编辑:添加 1) 屏幕截图 Android Studio preview pane not loading

和 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")
    }
}
kotlin android-studio android-jetpack-compose
1个回答
0
投票

我遇到了同样的问题,很愚蠢,我意识到我被缩小了太多,以至于文本在我的预览窗格中不可见。您尝试过使用缩放控件吗?

© www.soinside.com 2019 - 2024. All rights reserved.