Hemant Kumar
Hemant Kumar

Reputation: 21

Add click event on menu item

I am using bottom navigation bar, so I used three menu item in bottom navigation bar, my question is that I want to add some click eventon that button so when a user click on home button, it will come to the main activity from any activity and when user click on search bar, it will get a floating search bar in the bottom.

enter image description here

Upvotes: 2

Views: 2837

Answers (2)

Komal12
Komal12

Reputation: 3348

Put this code in onCreate() of your activity

    BottomNavigationView bottomNavigationView = (BottomNavigationView)findViewById(R.id.bottom_navigation);

    bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.home:
                //Add your action onClick
                break;
            case R.id.search:

                break;

            case R.id.favorite:

                break;
            }
        return false;
        }
    });

Upvotes: 4

鄭有維
鄭有維

Reputation: 265

Here is the tutorial teach you add bottom navigation bar step by step.

see :blog_iamsuleiman

Upvotes: 0

Related Questions