Is the title not centred is normal.
# compose
k
Is the title not centred is normal.
Iam using compose 1.0.0-alpha09
f
Your appbar probably renders below your system bar. You probably need to add top window inset height/padding top
k
Thanks
r
Can you share your code?
k
@rsktash you can see the link below https://chrisbanes.github.io/accompanist/insets/
@flosch I added like this but not working
Copy code
val insets = AmbientWindowInsets.current

Scaffold(
    modifier = Modifier.padding(top = insets.statusBars.top.dp),
r
@Karthick I think it is not insets issue. How are you rendering app bar? share your codd
z
Are you using
TopAppBar
or
AppBar
. By default
AppBar
does not center the content vertically. You can do that using
align
modifier or wrapping the content inside a
Row
and using
CenterVertically
alignment.
k
Copy code
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ComposeNavigationTheme {
                ProvideWindowInsets {
                    val navController = rememberNavController()
                    // A surface container using the 'background' color from the theme
                    Surface(color = MaterialTheme.colors.background) {
                        NavHost(navController = navController, startDestination = "first") {
                            composable("first") { FirstScreen(navController = navController) }
                            composable("second") { SecondScreen(navController = navController) }
                        }
                    }
                }
            }
        }
    }
}
Copy code
@Composable
fun FirstScreen(navController: NavController) {
    val insets = AmbientWindowInsets.current
    Scaffold(
        modifier = Modifier.padding(top = insets.statusBars.top.dp),
        topBar = {
            TopAppBar {
                Text("App Bar")
            }
        },
        floatingActionButton = {
            FloatingActionButton(onClick = { }) {
                Icon(Icons.Default.Check)
            }
        },
    ) {}
}
Using poco X2 phone, android 10
@flosch code added
j
Try this:
Copy code
TopAppBar(title = { Text("App Bar") })
Your code is probably using different TopAppBar composable (with
content
instead of
title
)
k
Wow super, thanks
👍 1