0

So I searched a lot but didn't get that how to create a toast like message that options menu provide on long tap on them. I'm sure there is a official way to do that, I want to create that message box on button long tap.

button.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        Toast.makeText(ActivityMain.this, "Have a good day", Toast.LENGTH_SHORT).show();
        return false;
    }
});

Result I want without using a custom toast sample given below

Sample

1 Answers1

0

You can do that by setting a button (with the onLongClickListener) as ActionView on the MenuItem, as described in the following answer:

https://stackoverflow.com/a/37899386/9863305

Philipp Poropat
  • 131
  • 1
  • 6