Last active
November 27, 2023 23:31
-
-
Save NonymousMorlock/1352a6b7f2a82684adb4f17b5412c1e3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.gdsc.layout_tutorial | |
import android.os.Bundle | |
import androidx.activity.ComponentActivity | |
import androidx.activity.compose.setContent | |
import androidx.compose.foundation.Image | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.border | |
import androidx.compose.foundation.layout.Arrangement | |
import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.Row | |
import androidx.compose.foundation.layout.Spacer | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.layout.width | |
import androidx.compose.foundation.shape.RoundedCornerShape | |
import androidx.compose.material3.MaterialTheme | |
import androidx.compose.material3.Surface | |
import androidx.compose.material3.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.draw.clip | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.res.colorResource | |
import androidx.compose.ui.res.painterResource | |
import androidx.compose.ui.text.font.FontWeight | |
import androidx.compose.ui.text.style.TextAlign | |
import androidx.compose.ui.tooling.preview.Preview | |
import androidx.compose.ui.unit.dp | |
import androidx.compose.ui.unit.sp | |
import com.gdsc.layout_tutorial.ui.theme.Layout_tutorialTheme | |
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
Layout_tutorialTheme { | |
// A surface container using the 'background' color from the theme | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = MaterialTheme.colorScheme.background | |
) { | |
Greeting("Android") | |
} | |
} | |
} | |
} | |
} | |
@Composable | |
fun Greeting(name: String, modifier: Modifier = Modifier) { | |
Text( | |
text = "Hello $name!", | |
modifier = modifier | |
) | |
} | |
@Composable | |
fun CustomButton(modifier: Modifier = Modifier, text: String) { | |
Box( | |
modifier = modifier | |
.clip(shape = RoundedCornerShape(90.dp)) | |
.background(color = colorResource(R.color.purple_200)) | |
) { | |
Text( | |
text, color = Color(0xffffffff), | |
modifier = Modifier.padding(10.dp), | |
) | |
} | |
} | |
@Preview(showBackground = true) | |
@Composable | |
fun GreetingPreview() { | |
Layout_tutorialTheme { | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = MaterialTheme.colorScheme.background | |
) { | |
Column(verticalArrangement = Arrangement.SpaceEvenly, horizontalAlignment = Alignment.CenterHorizontally) { | |
Image(painter = painterResource(R.drawable.tech), contentDescription = null) | |
Column(horizontalAlignment = Alignment.CenterHorizontally) { | |
Text("Let's work", fontSize = 30.sp, fontWeight = FontWeight.Medium) | |
Text( | |
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + | |
"tempor incididunt ut.", | |
textAlign = TextAlign.Center, | |
modifier = Modifier.padding(10.dp), | |
) | |
} | |
Row { | |
CustomButton(text = "Get Started") | |
Spacer(modifier = Modifier.width(50.dp)) | |
CustomButton(text = "Next") | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment