material-components / material-components/material-components-android

BottomNavigationView item's long click handling

Open
#1,368 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Good First Issue Widget: BottomNavigation
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

I want to handle long click on BottomNavigationView items for making own context menu like its in Instagram when user can hold "accout" icon and choose another profile.
I use this code:
```java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(listener);
bottomNavigationView.setSelectedItemId(R.id.nav_messages);

bottomNavigationView.findViewById(R.id.nav_profile).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Toast.makeText(getApplicationContext(), R.string.dark_mode, Toast.LENGTH_SHORT).show();
return true;
}
});

showFragment(new MessagesFragment());
}
```

But it works only when I start the app and holding item. If I start clicking on items and after that try to hold item again it does not work.
It seems like listener stops working after user starts communicating with BottomNavigationView.
Thank you.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the shown BottomNavigationView setup, selecting several items, and then long-pressing the profile item. Inspect the BottomNavigationView item handling to determine why the long-click listener stops responding; done means long-click handling still works after navigation between items.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.