RuleGame JetpackCompose | #1

MainActivity.kt


import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.rulegamecompose.rule_screen.RuleScreen
import com.example.rulegamecompose.ui.theme.GreenBg
import com.example.rulegamecompose.ui.theme.RuleGameComposeTheme

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
RuleGameComposeTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = GreenBg
) {
RuleScreen()
}
}
}
}
}

RuleScreen.kt

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Color.Companion.Red
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.rulegamecompose.R


@Composable
fun RuleScreen() {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.SpaceBetween
) {
Text(
modifier = Modifier.fillMaxWidth()
.height(100.dp)
.wrapContentHeight()
.wrapContentWidth(),
text = "0",
fontWeight = FontWeight.Bold,
fontSize = 35.sp,
color = Color.White
)
Box(modifier = Modifier
.weight(1f)
.fillMaxSize()){
Image(
painter = painterResource(id = R.drawable.ruleta),
contentDescription = "Ruleta",
modifier = Modifier.fillMaxSize()
)
Image(
painter = painterResource(id = R.drawable.flecha),
contentDescription = "Flecha",
modifier = Modifier.fillMaxSize()
)
}
Button(
onClick = { },
colors = ButtonDefaults.buttonColors(backgroundColor = Red),
modifier = Modifier.fillMaxWidth().padding(10.dp)
) {
Text(
text = "Start",
color = White
)
}

}
}

Color.kt

import androidx.compose.ui.graphics.Color

val Purple200 = Color(0xFFBB86FC)
val Purple500 = Color(0xFF6200EE)
val Purple700 = Color(0xFF3700B3)
val Teal200 = Color(0xFF03DAC5)
val GreenBg = Color(0xFF45AD5F)
val Reed = Color(0xFFF44336)

3 комментария для “RuleGame JetpackCompose | #1”

  1. Здравствуйте! У меня несколько проблем 1. Unresolved reference: drawable это ruleta и про flecha также. 2. Unresolved reference: Purple80 так со всеми цветами в Theme.kt. Это все пошло после изменений material. Как это исправить?

Добавить комментарий

Ваш адрес email не будет опубликован.