diff --git a/app/src/main/java/com/example/citrusclient/views/MainActivity.java b/app/src/main/java/com/example/citrusclient/views/MainActivity.java index 81d39a6..2401d75 100644 --- a/app/src/main/java/com/example/citrusclient/views/MainActivity.java +++ b/app/src/main/java/com/example/citrusclient/views/MainActivity.java @@ -1,14 +1,19 @@ package com.example.citrusclient.views; import android.os.Bundle; +import android.view.MenuItem; import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; +import androidx.fragment.app.Fragment; import com.example.citrusclient.R; +import com.google.android.material.bottomnavigation.BottomNavigationView; +import com.google.android.material.navigation.NavigationBarView; public class MainActivity extends AppCompatActivity { @@ -27,5 +32,36 @@ .replace(R.id.fragment_container, new MyBookshelfFragment()) .commit(); + setNavViewEvent(); + + } + + private void showFragment(Fragment fragment){ + getSupportFragmentManager().beginTransaction() + .replace(R.id.fragment_container, fragment) + .addToBackStack(null) + .commit(); + } + + private void setNavViewEvent(){ + BottomNavigationView navView = findViewById(R.id.bottomNavigationView); + navView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() { + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { + int itemId = menuItem.getItemId(); + if(itemId == R.id.book){// 本棚 + showFragment(new MyBookshelfFragment()); + } else if(itemId == R.id.search){//検索 + + } else if(itemId == R.id.home){//ホーム + + }else if(itemId == R.id.calendar){ //カレンダー + + }else if(itemId == R.id.face){//マイページ + + } + return true; + } + }); } } \ No newline at end of file