-
-
Save mediavrog/9345938 to your computer and use it in GitHub Desktop.
thank you!........
This only works for static xml Android resource menu. the dynamic menu adding command menu.add("text") will not work here as per my knowledge.
Usage example:
File: R.menu.menu_myactivity
<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">
<item
android:id="@+id/action_settings"
android:title="@string/action_settings"
android:icon="@drawable/ic_launcher"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
Java part
IconizedMenu PopupMenu;
final Button _anchor = (Button) findViewById(R.id.button);
_anchor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showPopUp(_anchor);
}
});
void showPopUp(View anchorView)
{
PopupMenu = new IconizedMenu(getWindow().getContext(), anchorView);
Menu menu = PopupMenu.getMenu();
MenuInflater inflater = PopupMenu.getMenuInflater();
inflater.inflate(R.menu.menu_myactivity, PopupMenu.getMenu());
PopupMenu.show();
}
Thanks mediavrog.
It's great! Thank you so much.
@showrav017 sir what are you trying to show? about the code you share? sorry i'm just starting to learn android programming :)
@mediavrog is it possible to show icons inside popup menu in grid view? i wanted to know to implement? just starting to learn android programming.
Thank you! Works perfectly!
Heads up for those using appcombat v7:23.1.1 and up, they changed the packages slightly.
import android.support.v7.view.SupportMenuInflater;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.view.menu.MenuPopupHelper;
import android.support.v7.view.menu.MenuPresenter;
import android.support.v7.view.menu.SubMenuBuilder;
Just remove .internal from there :)
@mediavrog thank you very much for this awesome gist , it it that what i am looking for it work fine have little bit size issue
i have 8 item in context menu but it shows just only one item
if anyone have slimier issue or have any workaround then let me know
Thank you very much
How can i use type face for menu text?
I recommend to add
public void setGravity(int gravity) { mPopup.setGravity(gravity); }
considering need to align the popup
Hey guys, i got an error like this :
Failed to resolve attribute at index 6
Can anyone help me :) thanks
Can we have this menu shown above the anchorView?
I am using this inside a RecyclerView's item and it scrolls the Card just to show this popupMenu.
tedchirvasiu thanks!
mPopup.setCallback(this); doesn't work since latest AppCompat lib
Exactly. Appcompat 24.0.0 mPopup.setCallback can't invoke.
use mPopup.setPresenterCallback(this); instead
@kimcy929
@abaxxx
Thank you so much.
@tuinui
Thank u so much.. worked like a charm.
Thank you so much. @tuinui
How to remove the empty space if we are not using the text??
Support v7 MenuPopupHelper
is now hidden and restricted to LIBRARY_GROUP 😢
More details here:
https://stackoverflow.com/questions/44969577/support-v7-menupopuphelper-is-now-hidden-and-restricted-to-library-group
@miankhalid Did you found a work around. MenuBuilder and MenuPopupHelper both are now restricted to LIBRARY_GROUP
Seems like the only way to use it currently is through reflection https://resocoder.com/2018/02/02/popup-menu-with-icons-android-kotlin-tutorial-code/
Thank you! Works perfectly! Heads up for those using appcombat v7:23.1.1 and up, they changed the packages slightly.
import android.support.v7.view.SupportMenuInflater; import android.support.v7.view.menu.MenuBuilder; import android.support.v7.view.menu.MenuPopupHelper; import android.support.v7.view.menu.MenuPresenter; import android.support.v7.view.menu.SubMenuBuilder;
Just remove .internal from there :)
And now, you replace import android.support.v7
with androidx.appcompat
import androidx.appcompat.view.menu.MenuBuilder;
import androidx.appcompat.view.menu.MenuPopupHelper;
import androidx.appcompat.view.menu.MenuPresenter;
import androidx.appcompat.view.menu.SubMenuBuilder;
Usage example: