Skip to content

Commit

Permalink
[Feat/#22] Bottom navigation 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ss99x2002 committed Jul 9, 2023
1 parent 24571f8 commit 8f7928e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,39 @@ import com.sopt.umbba_android.R
import com.sopt.umbba_android.databinding.ActivityMainBinding
import com.sopt.umbba_android.presentation.home.HomeFragment
import com.sopt.umbba_android.presentation.qna.QuestionAnswerActivity
import com.sopt.umbba_android.presentation.setting.SettingFragment
import com.sopt.umbba_android.util.binding.BindingActivity

class MainActivity :BindingActivity<ActivityMainBinding>(R.layout.activity_main){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
initView()
setBottomNav()
}

private fun initView(){
val currentFragment = supportFragmentManager.findFragmentById(R.id.fcv_main)
if (currentFragment == null) {
changeFragment(HomeFragment())
}
}
private fun setBottomNav(){
binding.bnvMain.run(){
setOnItemSelectedListener {
changeFragment(
when(it.itemId){
R.id.menu_home -> HomeFragment()
R.id.menu_setting -> SettingFragment()
else -> HomeFragment()
}
)
true
}
}
}
private fun changeFragment(fragment: Fragment) {
supportFragmentManager.beginTransaction()
.replace(R.id.fcv_main, fragment)
.commit()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home
super.onViewCreated(view, savedInstanceState)
setBackground()
}

private fun setBackground(){
with(binding){
ivBackground.load("https://i.ibb.co/sRV9Vr4/iv-maru.jpg")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class QuestionAnswerActivity :

private fun setBlurText(isBlur: Boolean) {
with(binding) {
tvAnswerOther.setLayerType(View.LAYER_TYPE_SOFTWARE, null).apply{
tvAnswerOther.setLayerType(View.LAYER_TYPE_SOFTWARE, null).apply {
if (isBlur) tvAnswerOther.paint.maskFilter =
BlurMaskFilter(13f, BlurMaskFilter.Blur.NORMAL)
else tvAnswerOther.paint.maskFilter = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.sopt.umbba_android.presentation.setting

import android.os.Bundle
import android.view.View
import com.sopt.umbba_android.R
import com.sopt.umbba_android.databinding.FragmentSettingBinding
import com.sopt.umbba_android.util.binding.BindingFragment

class SettingFragment:BindingFragment<FragmentSettingBinding>(R.layout.fragment_setting) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
}
15 changes: 11 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
android:layout_height="match_parent"
tools:context=".presentation.MainActivity">

<FrameLayout
android:id="@+id/fragment_fv"
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fcv_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"/>

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bnv_main"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:itemIconSize="24dp"
app:menu="@menu/menu_bottom"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
15 changes: 15 additions & 0 deletions app/src/main/res/menu/menu_bottom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_home"
android:title=""
android:icon="@drawable/ic_close" />
<item
android:id="@+id/menu_list"
android:title="리스트"
android:icon="@drawable/ic_close" />
<item
android:id="@+id/menu_setting"
android:title="설정"
android:icon="@drawable/ic_close" />
</menu>

0 comments on commit 8f7928e

Please sign in to comment.