Skip to content

Instantly share code, notes, and snippets.

@rocboronat
Last active August 29, 2015 14:06
Show Gist options
  • Save rocboronat/940b43b116c11aa9c52b to your computer and use it in GitHub Desktop.
Save rocboronat/940b43b116c11aa9c52b to your computer and use it in GitHub Desktop.
Show a PopupWindow with negative margin on a MenuItem of the ActionBar
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_listoffers, menu);
new Handler().post(new Runnable() {
@Override
public void run() {
final View menuItemView = findViewById(R.id.action_search);
View layoutOfPopup = getLayoutInflater().inflate(R.layout.popup_help_search, null);
popupMessage = new PopupWindow(layoutOfPopup, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popupMessage.setContentView(layoutOfPopup);
popupMessage.showAsDropDown(menuItemView, -20, -20); //It's friday night, but you mustn't use magic numbers in real code!
}
});
return super.onCreateOptionsMenu(menu);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment