Instantly share code, notes, and snippets.
Created
May 27, 2025 03:04
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
-
Save Sprajapati123/d7339739aa8240e841678e920943e6ea 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.example.c36b | |
| import android.app.Activity | |
| import android.os.Bundle | |
| import androidx.activity.ComponentActivity | |
| import androidx.activity.compose.setContent | |
| import androidx.activity.enableEdgeToEdge | |
| import androidx.compose.foundation.Image | |
| import androidx.compose.foundation.background | |
| import androidx.compose.foundation.border | |
| import androidx.compose.foundation.horizontalScroll | |
| 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.fillMaxWidth | |
| import androidx.compose.foundation.layout.height | |
| import androidx.compose.foundation.layout.padding | |
| import androidx.compose.foundation.layout.size | |
| import androidx.compose.foundation.layout.width | |
| import androidx.compose.foundation.lazy.LazyColumn | |
| import androidx.compose.foundation.lazy.LazyRow | |
| import androidx.compose.foundation.lazy.grid.GridCells | |
| import androidx.compose.foundation.lazy.grid.LazyVerticalGrid | |
| import androidx.compose.foundation.rememberScrollState | |
| import androidx.compose.foundation.shape.CircleShape | |
| import androidx.compose.foundation.shape.RoundedCornerShape | |
| import androidx.compose.foundation.verticalScroll | |
| import androidx.compose.material.icons.Icons | |
| import androidx.compose.material.icons.filled.ArrowBack | |
| import androidx.compose.material.icons.filled.Home | |
| import androidx.compose.material.icons.filled.Person | |
| import androidx.compose.material.icons.filled.Search | |
| import androidx.compose.material.icons.filled.Settings | |
| import androidx.compose.material3.Button | |
| import androidx.compose.material3.ExperimentalMaterial3Api | |
| import androidx.compose.material3.Icon | |
| import androidx.compose.material3.IconButton | |
| import androidx.compose.material3.NavigationBar | |
| import androidx.compose.material3.NavigationBarItem | |
| import androidx.compose.material3.Scaffold | |
| import androidx.compose.material3.Text | |
| import androidx.compose.material3.TopAppBar | |
| import androidx.compose.material3.TopAppBarDefaults | |
| import androidx.compose.runtime.Composable | |
| import androidx.compose.runtime.getValue | |
| import androidx.compose.runtime.mutableStateOf | |
| import androidx.compose.runtime.remember | |
| import androidx.compose.runtime.setValue | |
| 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.graphics.vector.ImageVector | |
| import androidx.compose.ui.layout.ContentScale | |
| import androidx.compose.ui.platform.LocalContext | |
| import androidx.compose.ui.res.painterResource | |
| import androidx.compose.ui.tooling.preview.Preview | |
| import androidx.compose.ui.unit.dp | |
| import com.example.c36b.ui.theme.C36BTheme | |
| class NaviigationActivity : ComponentActivity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| enableEdgeToEdge() | |
| setContent { | |
| NavigationBody() | |
| } | |
| } | |
| } | |
| @OptIn(ExperimentalMaterial3Api::class) | |
| @Composable | |
| fun NavigationBody() { | |
| data class BottomNavItem(val label: String, val icon: ImageVector) | |
| val bottomNavItems = listOf( | |
| BottomNavItem("Home", Icons.Default.Home), | |
| BottomNavItem("Search", Icons.Default.Search), | |
| BottomNavItem("Profile", Icons.Default.Person) | |
| ) | |
| var selectedIndex by remember { mutableStateOf(0) } | |
| Scaffold( | |
| bottomBar = { | |
| NavigationBar { | |
| bottomNavItems.forEachIndexed { index, item -> | |
| NavigationBarItem( | |
| icon = { Icon(item.icon, contentDescription = item.label) }, | |
| label = { Text(item.label) }, | |
| selected = selectedIndex == index, | |
| onClick = { selectedIndex = index } | |
| ) | |
| } | |
| } | |
| }, | |
| ) { innerPadding -> | |
| Box( | |
| modifier = Modifier | |
| .padding(innerPadding) | |
| .fillMaxSize(), | |
| contentAlignment = Alignment.Center | |
| ) { | |
| when (selectedIndex) { | |
| 0 -> Home1() | |
| 1 -> Home2() | |
| 2 -> Home3() | |
| } | |
| } | |
| } | |
| } | |
| @Preview(showBackground = true) | |
| @Composable | |
| fun PrevNavigation() { | |
| NavigationBody() | |
| } | |
| @Composable | |
| fun Home1() { | |
| Column( | |
| modifier = Modifier | |
| .fillMaxSize() | |
| .background(color = Color.Gray) | |
| ) { | |
| } | |
| } | |
| @Composable | |
| fun Home2() { | |
| Column( | |
| modifier = Modifier | |
| .fillMaxSize() | |
| .background(color = Color.Yellow) | |
| ) { | |
| } | |
| } | |
| @Composable | |
| fun Home3() { | |
| Column( | |
| modifier = Modifier | |
| .fillMaxSize() | |
| .background(color = Color.Green) | |
| ) { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment