Reputation: 798
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:
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.
Upvotes: 0
Views: 71
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