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 { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_main); ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); showFragment(new MyBookshelfFragment()); setNavViewEvent(); } public 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){//ホーム showFragment(new HomeFragment()); }else if(itemId == R.id.calendar){ //カレンダ }else if(itemId == R.id.face){//マイページ } return true; } }); } }