Kotlin Compose 底部栏
Posted 安果移不动
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kotlin Compose 底部栏相关的知识,希望对你有一定的参考价值。
package com.anguomob.compose.ui.screens
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DateRange
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Person
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.Color
import com.anguomob.compose.model.NavigationItem
@Composable
fun MainFrame()
val navigationItems = listOf(
NavigationItem(title = "学习", icon = Icons.Filled.Home),
NavigationItem(title = "任务", icon = Icons.Filled.DateRange),
NavigationItem(title = "我的", icon = Icons.Filled.Person),
)
var currentNavigationIndex by remember
mutableStateOf(0)
Scaffold(bottomBar =
BottomNavigation(
backgroundColor = MaterialTheme.colors.surface
)
navigationItems.forEachIndexed() index, navigationItem ->
BottomNavigationItem(
selected = currentNavigationIndex == index,
onClick =
currentNavigationIndex = index
,
icon =
Icon(imageVector = navigationItem.icon, contentDescription = null)
,
label =
Text(text = navigationItem.title)
,
alwaysShowLabel = false,
selectedContentColor = Color(0xFF149ee7),
unselectedContentColor = Color(0xFF999999)
)
)
Text(text = "Current navagation itme:$currentNavigationIndex")
以上是关于Kotlin Compose 底部栏的主要内容,如果未能解决你的问题,请参考以下文章
Jetpack Compose - 导航 - 脚手架 + NavHost 不工作
android手机安全卫士Kotlin漫画支付宝动画沉浸状态栏等源码
Android compose wanandroid app之分类页面的实现