0

I have a requirement that action Overflow menu icon should show in fragment, but not activity.

Code:

 @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.filter:
                openFilterDialog();
                return true;
            default:
                break;
        }

        return false;
    }


@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_mail_list, menu);
        return true;
    }

menu xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.dwisehealthcare.pmstablet.consult.activity.ConsultActivity">

    <item
        android:id="@+id/filter"
        android:title="Filter"
        android:icon="@drawable/ic_baseline_filter_list_24"
        app:showAsAction="always" />

</menu>

I searched, but everyone is talking about menu item, not action icon.

1 Answers1

0

Try this link may be it will help you, with the help of this you can add menu anywhere you want.Just add an ImageView to that fragment and when you click that imageView you create a PopUpMenu

Md Aman
  • 340
  • 3
  • 10