简体   繁体   English

使用 jetpack compose 添加文本元素?

[英]Add a text element using jetpack compose?

Im trying lesson 1我正在尝试第 1 课

https://developer.android.com/jetpack/compose/tutorial?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fcompose%23article-https%3A%2F%2Fdeveloper.android.com%2Fjetpack%2Fcompose%2Ftutorial https://developer.android.com/jetpack/compose/tutorial?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fcompose%23article-https%3A%2F%2Fdeveloper.android.com% 2Fjetpack%2Fcompose%2F教程

However, the first step Add a text element is not working, i just get a blank screen.但是,第一步添加文本元素不起作用,我只是得到一个空白屏幕。

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Text("Hello world!")
        }
    }
}

What may be happening, is that since you're not defining a theme to work with, the text color might be white, as well as the background.可能发生的情况是,由于您没有定义要使用的主题,因此文本颜色和背景可能都是白色的。

If your background is white, try to replace如果您的背景是白色的,请尝试替换

Text("Hello world!")

with

Text(text = "Hello world!", color = Color.Black)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM