Untitled
unknown
plain_text
11 days ago
4.1 kB
5
Indexable
private void initNavigationView() { mBottomNavigation = findViewById(R.id.main__bottom_navigation); setupCustomBottomNavigationView(mBottomNavigation); navGraphIds = Arrays.asList( R.navigation.navigation_home, R.navigation.navigation_navigation, R.navigation.nav_maintenance, R.navigation.navigation_profile); mBottomNavigation.setupWithNavController( navGraphIds, getSupportFragmentManager(), R.id.nav_host_fragment_activity_main, getIntent(),viewModel, this); // mBottomNavigation. setOnItemSelectedListener(item -> { // if(item.getItemId() == R.id.navigation_profile){ // if(customTab != null){ // customTab.setBackgroundColor(getResources().getColor(R.color.profile_bg)); // ImageView tabIcon = customTab.findViewById(R.id.tab_icon); // TextView tabTitle = customTab.findViewById(R.id.tab_title); // tabTitle.setTextColor(getColor(R.color.white)); // tabTitle.setText("Cancel"); // tabIcon.animate().scaleX(1.5f).scaleY(1.5f).setDuration(300).start(); // tabIcon.setImageResource(R.drawable.cancel); // } // // } // return false; // }); } private void setupCustomBottomNavigationView(SavedBottomNavigationView bottomNavigationView) { @SuppressLint("RestrictedApi") BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottomNavigationView.getChildAt(0); for (int i = 0; i < menuView.getChildCount(); i++) { View itemView = menuView.getChildAt(i); MenuItem menuItem = bottomNavigationView.getMenu().getItem(i); // Clear default content menuItem.setTitle(""); menuItem.setIcon(null); @SuppressLint("RestrictedApi") BottomNavigationItemView item = (BottomNavigationItemView) itemView; // Inflate custom tab layout if(menuItem.getItemId() == R.id.navigation_profile){ profileTab = LayoutInflater.from(this).inflate(R.layout.profile_tab, item, false); }else if(menuItem.getItemId() == R.id.nav_maintenance){ maintnanceTab = LayoutInflater.from(this).inflate(R.layout.maintenance_tab, item, false); } else if(menuItem.getItemId() == R.id.navigation_navigation){ navigationTab = LayoutInflater.from(this).inflate(R.layout.navigation_tab, item, false); } else if(menuItem.getItemId() == R.id.navigation_home){ homeTab = LayoutInflater.from(this).inflate(R.layout.home_bottom_tab, item, false); } ImageView tabIcon = homeTab.findViewById(R.id.tab_icon); TextView tabTitle = homeTab.findViewById(R.id.tab_title); // Set icons and text dynamically based on the menu item switch (menuItem.getItemId()) { case R.id.navigation_home: tabIcon.setImageResource(R.drawable.home2); tabTitle.setText("Home"); break; case R.id.navigation_navigation: tabIcon.setImageResource(R.drawable.navigation_module2); tabTitle.setText("Navigation"); break; case R.id.nav_maintenance: tabIcon.setImageResource(R.drawable.incident_module2); tabTitle.setText("Maintenance"); break; case R.id.navigation_profile: tabIcon.setImageResource(R.drawable.profile_icon); tabTitle.setText("Profile"); break; } // Apply the custom view item.addView(homeTab); } }
Editor is loading...
Leave a Comment