MainActivity.kt
package com.cfsuman.jetpackcompose
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.Color
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {GetScaffold()}
}
@Composable
fun GetScaffold() {
Scaffold(
topBar = {TopAppBar(
title = {Text(text = "Compose - Screen Layout Direction")},
backgroundColor = Color(0xFF5F9EA0),
)},
content = { MainContent() },
backgroundColor = Color(0xFFC2B280)
)
}
@Composable
fun MainContent() {
val configuration = LocalConfiguration.current
val layoutDirection = configuration.layoutDirection
Box(Modifier.fillMaxSize().padding(12.dp)) {
Text(
text = "Screen layout Direction" +
"\n${getLayoutDirectionName(layoutDirection)}",
fontSize = 24.sp,
)
}
}
}
fun getLayoutDirectionName(value:Int):String{
return when (value) {
0 -> {
"LTR : Left To Right"
}
1 -> {
"RTL : Right To Left"
}
else -> {"Error!"}
}
}
- jetpack compose - Snackbar action
- jetpack compose - How to use AndroidView
- jetpack compose - How to update AndroidView
- jetpack compose - How to use navigation controller
- jetpack compose - Navigate with argument
- jetpack compose - Room add remove update
- jetpack compose - How to use WebView
- jetpack compose - Background brush
- jetpack compose - Combined clickable
- jetpack compose - How to use TabRow
- jetpack compose - TabRow indicator color
- jetpack compose - Get screen width height in dp
- jetpack compose - How to change StatusBar color
- jetpack compose - How to change NavigationBar color
- jetpack compose - How to change SystemBars color