Skip to content

Instantly share code, notes, and snippets.

View hsmnzaydn's full-sized avatar
🎈
Working from home

Hüseyin Serkan Özaydin hsmnzaydn

🎈
Working from home
View GitHub Profile
MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
content = content
)
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> DarkColorScheme
else -> LightColorScheme
}
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
LazyColumn(){
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
@ExperimentalMaterial3Api
@ExperimentalMaterial3Api
@Composable
fun ItemView() {
Card( // Material 3'te Card şuan betada
modifier = Modifier.padding(8.dp),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surface, // Burada kart kullandığımız için Material Design surface rengini kullanmamız gerektiğini söylüyor
),
shape = MaterialTheme.shapes.large,
) {
@Composable
fun MaterialTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color android 12 ve üstü için geçerli
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
private val LightColorScheme = lightColorScheme(
background = lightBackground,
primary = lightPrimary,
secondary = lightSecondary,
surface = lightSurface,
onSurface = lightOnSurface
)
private val DarkColorScheme = darkColorScheme(
background = darkBackground,
primary = darkPrimary,
secondary = darkSecondary,
surface = darkSurface,
onSurface = darkOnSurface
)
val Typography = Typography(
bodyLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.5.sp
),
titleLarge = TextStyle(
fontFamily = FontFamily.Default,
val lightPrimary = Color(0xFFA784F7)
val lightSecondary = Color(0xFF9B75F3)
val lightBackground = Color(0xFFC2AEF0)
val lightSurface = Color(0xFFA27EF0)
val lightOnSurface = Color(0xFF564481)
val darkPrimary = Color(0xFF100035)
val darkSecondary = Color(0xFF1F0166)
val darkBackground = Color(0xFF1D005F)