Skip to content

Commit

Permalink
feat: #6 홈 화면 BottomNavigation 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyobeen-Park committed Apr 19, 2024
1 parent 86a646b commit 28db13e
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 7 deletions.
12 changes: 6 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@
android:exported="false"
android:label="@string/app_name"
android:theme="@style/Theme.NOWSOPTAndroid">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SignupActivity"
android:exported="false"
android:label="@string/app_name"
android:theme="@style/Theme.NOWSOPTAndroid">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeActivity"
android:exported="false"
android:label="@string/app_name"
android:theme="@style/Theme.NOWSOPTAndroid">
</activity>
</application>

Expand Down
120 changes: 120 additions & 0 deletions app/src/main/java/com/sopt/now/compose/HomeActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.sopt.now.compose

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.sopt.now.compose.ui.theme.NOWSOPTAndroidTheme

class HomeActivity: ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
NOWSOPTAndroidTheme {
Surface (
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
){
HomeScreen()
}
}
}
}

data class BottomNavigationItem (
val Icon : ImageVector,
val label : String
)

@OptIn(ExperimentalMaterial3Api::class)
@Preview(showBackground = true)
@Composable
private fun HomeScreen() {
var selectedItem by remember { mutableIntStateOf(0) }
val items = listOf(
BottomNavigationItem(
Icon = Icons.Filled.Home,
label = "Home"
),
BottomNavigationItem(
Icon = Icons.Filled.Search,
label = "Search"
),
BottomNavigationItem(
Icon = Icons.Filled.Person,
label = "Mypage"
)
)

Scaffold (
topBar = {
TopAppBar(
colors = topAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
titleContentColor = MaterialTheme.colorScheme.primary
),
title = {
Text("NOW SOPT ANDROID")
}
)
},
bottomBar = {
NavigationBar {
items.forEachIndexed {index, item ->
NavigationBarItem(
icon = { Icon(item.Icon, contentDescription = item.label)},
label = { Text(item.label)},
selected = selectedItem == index ,
onClick = { selectedItem = index }
)
}
}
}
) { innerPadding ->
Column (
modifier = Modifier
.padding(innerPadding)
.padding(horizontal = 30.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
when(selectedItem) {
0 -> Text("HOME")
1 -> Text("SEARCH")
2 -> Text("MYPAGE")
}
}

}

}



}
2 changes: 1 addition & 1 deletion app/src/main/java/com/sopt/now/compose/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fun Login(signupId : String?, signupPw : String?, nickname : String?, mbti : Str
onClick = {
if(id == signupId && pw == signupPw) {
Toast.makeText(context, "로그인에 성공했습니다.", Toast.LENGTH_SHORT).show()
Intent(context, MainActivity::class.java).apply {
Intent(context, HomeActivity::class.java).apply {
putExtra("id", id)
putExtra("pw", pw)
putExtra("nickname", nickname)
Expand Down

0 comments on commit 28db13e

Please sign in to comment.