This version occurs when the android version is <16. The original call: public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) should be changed to public void showAsDropDown(View anchor, int xoff, int yoff). That is, remove the last gravity parameter:
Roughly written:
if (Build.VERSION.SDK_INT >= 16)
dialog.showAsDropDown(getSupportActionBar().getCustomView(), 500, 0, Gravity.END);
else
dialog.showAsDropDown(getSupportActionBar().getCustomView(), 500, 0);