D.Zou
D.Zou

Reputation: 798

android studio preview not rendering my changes

I am trying to do this example from Android Developer course for Happy birthday, but in my preview screen it never renders the 'from bob'.

This is the the stage I am at:

https://developer.android.com/codelabs/basic-android-kotlin-compose-text-composables?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-1-pathway-3%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-text-composables#6

package com.example.happybirthday

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Row
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 androidx.compose.ui.unit.sp
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
                ) {

                }
            }
        }
    }
}

@Composable
fun GreetingText(message: String, from: String, modifier: Modifier= Modifier){
    Row {
        Text(
            text = message,
            fontSize = 100.sp,
            lineHeight = 110.sp
        )
        Text(
            text = from,
            fontSize = 36.sp,
            lineHeight = 20.sp

        )
    }
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    HappyBirthdayTheme {
        GreetingText(message ="Happy Birthday Android", from = "from bob")
    }
}

And on the preview screen it only shows Happy Birthday Android, but the 'from bob' is missing. enter image description here

Upvotes: 0

Views: 71

Answers (1)

tyg
tyg

Reputation: 15195

Bob is there, he just doesn't fit the window because the greetings mesage fills it up entirely. Reduce the fontSize of the message to 20.sp, for example, and Bob will return.

Upvotes: 1

Related Questions