0

Is there any way to implement Popup Window's showAsDropDown function animation? For example, a way to show Dialog with this drop down animation?

I can't use PopupWindow because app crashes when I set errors via EditText.setError(); - it is known issue and it is still not fixed.

Proof: Exception when try to setError() in an editText inside a Popup Window look at the Kantesh last comment.

Community
  • 1
  • 1
Matt
  • 191
  • 1
  • 6

1 Answers1

0

you can use PopUp Menu instead and its implemmented as follow :

public void showPopUp(final View view) {


    PopupMenu popup = new PopupMenu(this, view);
    MenuInflater inflater = popup.getMenuInflater();

    //Note that R.menu.option is a menu in the menu.xml
    inflater.inflate(R.menu.options, popup.getMenu());

    /* Force icons to show if you want to display icons
    Object menuHelper = null;
    Class[] argTypes;
    try {
        Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
        fMenuHelper.setAccessible(true);
        menuHelper = fMenuHelper.get(popup);
        argTypes = new Class[] { boolean.class };
        menuHelper.getClass().getDeclaredMethod("setForceShowIcon", argTypes).invoke(menuHelper, true);
    } catch (Exception e) {
        popup.show();
        return;
    }
    */
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.item1:
                    // do thing when item1 clicked
                    break;

                case R.id.item2:

                    // do thing when item2 licked                        break;

                default:
                    return false;
            }
            return false;
        }
    });

    popup.show();


} 

on Xml you have to add new menu as follow :

in Menu Folder add new Xml File call it whatever then inside of it add the option you want them to appear for example mine is options.xml :

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/item1"
    android:showAsAction="ifRoom|withText"
    android:title="item1"
    android:visible="true"/>

<item
    android:id="@+id/item2"
    android:showAsAction="ifRoom|withText"
    android:title="item2"
    android:visible="true"/>

</menu>

i hope this what you want and the result is like this :

enter image description here

Mohammad Salem
  • 1,113
  • 9
  • 15