samedi 18 janvier 2020

Check multiple items on Navigation Bar

I have a BottomNavigationBar with 4 items and i want multiple items to be checkable. I know that this bar is used for navigating through activities but i want more than 1 item to be chackable

If not checkable atleast change the text color or the icon color of items individually instead of changing them as a whole

Code

        final BottomNavigationView bottomNavigation = findViewById(R.id.bottom_navigation);
    bottomNavigation.getMenu().setGroupCheckable(0, true, true);
    BottomNavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener =
            new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    switch (item.getItemId()) {
                        case R.id.vpn:

                        bottomNavigation.getMenu().findItem(R.id.home).setVisible(false);
                        bottomNavigation.getMenu().findItem(R.id.home).setChecked(true);
                        bottomNavigation.getMenu().findItem(R.id.theme).setTitle("ON");
                        Toast.makeText(getApplicationContext(),"VPN",Toast.LENGTH_SHORT).show();
                            return true;

                        case R.id.incognito:
                            Toast.makeText(getApplicationContext(),"Private",Toast.LENGTH_SHORT).show();
                            return true;

                        case R.id.theme:
                            Toast.makeText(getApplicationContext(),"Theme",Toast.LENGTH_SHORT).show();
                            return true;
                        case R.id.home:

                            Toast.makeText(getApplicationContext(),"Home",Toast.LENGTH_SHORT).show();
                            return true;
                    }
                    return false;
                }
            };
    bottomNavigation.setOnNavigationItemSelectedListener(navigationItemSelectedListener);

The only piece of code which acts on a single item till now is visibility, enabled and title of an item. I want to change icon color and/or text color the same way but with multiple items together. Help me out




Aucun commentaire:

Enregistrer un commentaire