Created
February 9, 2025 16:24
-
-
Save EleniVrabec/8a3736b1bc87009415e02ec0838c30aa to your computer and use it in GitHub Desktop.
Uppgift 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.uppgift1 | |
import android.os.Bundle | |
import androidx.activity.ComponentActivity | |
import androidx.activity.compose.setContent | |
import androidx.activity.enableEdgeToEdge | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.border | |
import androidx.compose.foundation.layout.Arrangement | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.Row | |
import androidx.compose.foundation.layout.fillMaxHeight | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.foundation.layout.fillMaxWidth | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.layout.width | |
import androidx.compose.material3.Button | |
import androidx.compose.material3.ButtonDefaults | |
import androidx.compose.material3.Scaffold | |
import androidx.compose.material3.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.mutableStateOf | |
import androidx.compose.runtime.remember | |
import androidx.compose.runtime.setValue | |
import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.graphics.RectangleShape | |
import androidx.compose.ui.tooling.preview.Preview | |
import androidx.compose.ui.unit.dp | |
import androidx.compose.ui.unit.sp | |
import com.example.uppgift1.ui.theme.Uppgift1Theme | |
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
enableEdgeToEdge() | |
setContent { | |
Uppgift1Theme { | |
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> | |
MainScreen() | |
} | |
} | |
} | |
} | |
} | |
@Composable | |
fun MainScreen() { | |
var number by remember { mutableStateOf(0) } | |
Column ( | |
modifier = Modifier | |
.fillMaxSize() | |
.background(Color.Blue) | |
.padding(top = 100.dp), | |
horizontalAlignment = Alignment.CenterHorizontally) | |
{ | |
Row(modifier = Modifier | |
.padding(10.dp) | |
.fillMaxWidth() | |
.background(Color.Green), | |
horizontalArrangement = Arrangement.Center, | |
verticalAlignment = Alignment.CenterVertically) | |
{ | |
Text("UPGIFT 1", fontSize = 70.sp, color = Color.Black, modifier = Modifier.padding(bottom = 20.dp)) | |
} | |
Column(modifier = Modifier.padding(top = 10.dp).fillMaxHeight(), | |
horizontalAlignment = Alignment.CenterHorizontally, | |
verticalArrangement = Arrangement.Center) { | |
if (number < 10) { | |
Button( | |
onClick = { number++ }, | |
modifier = Modifier | |
.padding(top = 20.dp) | |
.width(150.dp) | |
.background(Color.Red), | |
shape = RectangleShape, | |
colors = ButtonDefaults.buttonColors(Color.Red) | |
) { | |
Text("PLUS", color = Color.Black, fontSize = 20.sp) | |
} | |
} | |
Text(text = number.toString(), fontSize = 200.sp) | |
if (number > 0) { | |
Button( | |
onClick = { number-- }, | |
modifier = Modifier | |
.padding(top = 20.dp) | |
.width(150.dp) | |
.background(Color.Red), | |
shape = RectangleShape, | |
colors = ButtonDefaults.buttonColors(Color.Red) | |
){ | |
Text("MINUS", color = Color.Black, fontSize = 20.sp) | |
} | |
} | |
} | |
} | |
} | |
@Preview(showBackground = true) | |
@Composable | |
fun GreetingPreview() { | |
Uppgift1Theme { | |
MainScreen() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment