Белый экран в моем приложении с помощью Jetpack Compose (Android ide)Android

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Гость
 Белый экран в моем приложении с помощью Jetpack Compose (Android ide)

Сообщение Гость »


I was using Android Studio for Jetpack Compos, and now I do not have my device because I am in another country. I went to Android ide and was trying to make an application using Compos, but the expected result in both cases is a white screen. Hope help me fast to solve it
Here is my code

Код: Выделить всё

package com.example.birthdayproject

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.material3.OutlinedTextField
import androidx.compose.ui.unit.dp
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import com.example.birthdayproject.ui.theme.MyComposeApplicationTheme
import androidx.compose.material3.ExperimentalMaterial3Api
class MainActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3Api::class)

@Composable
fun EnterNameScreen(setName: (String) -> Unit) {
var name by remember { mutableStateOf("") }

Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = "Enter Birthday Person's Name:")
Spacer(modifier = Modifier.height(16.dp))
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = { Text("Name") }
)
Spacer(modifier = Modifier.height(16.dp))
Button(onClick = { setName(name) }) {
Text("Show Birthday Greeting")
}
}
}

@Composable
fun BirthdayGreeting(name: String) {
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Icon(
painter = painterResource(id = R.drawable.birthday_cake), // Replace with your icon
contentDescription = "Birthday Cake"
)
Spacer(modifier = Modifier.height(16.dp))
Text(text = "Happy Birthday, $name!")
// Add more birthday-themed elements here (optional)
}
}

@Override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyComposeApplicationTheme {
var showGreeting by remember { mutableStateOf(false) }
var name by remember { mutableStateOf("") }

if (!showGreeting) {
EnterNameScreen { enteredName ->
name = enteredName
showGreeting = true
}
} else {
BirthdayGreeting(name)
}
}
}
}
}
}
And the results
(Изображение)](Изображение)


Источник: https://stackoverflow.com/questions/781 ... ndroid-ide
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»