samedi 9 mai 2020

I can't use API reflection on androidx.appcompat:appcompat:1.1.0

First, sorry for my english, but i'm not speak it.

I have a problem wiht androidx.appcompat:appcompat:1.1.0. It's a new problem because on androidx.appcompat:appcompat:1.0.2 it is not exist.

I have a code that use reflection for get mPopup Field from spinner and set its height. It's work very well on appcompat:1.0.2 but not on androidx.appcomppat:appcompat:1.1.0.

The code is

` private void setPopUp() {

    try {
        Field popup = getPopupField();

        // Get private mPopup member variable and try cast to ListPopupWindow
        final android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(spinner);

        // Set popupWindow height to max - 40dp
        spinner.post(new Runnable() {
            @Override
            public void run() {
                Rect r = new Rect();
                spinner.getGlobalVisibleRect(r);
                int height = 200;
                popupWindow.setHeight(height);
            }
        });
    } catch (NoClassDefFoundError | ClassCastException | IllegalAccessException e) {
        // silently fail...
    }


}

private static Field getPopupField () {
    if (sPopupField == null) {
        try {
            Field popup = Spinner.class.getDeclaredField("mPopup");
            popup.setAccessible(true);

            sPopupField = popup;
        } catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException e) {
            // silently fail...
        }
    }
    return sPopupField;
}

`

I read about a bugs on a new appcompatActivity from appcompat:1.1.0. However i can't find the solution for my problem.

Anybody can help me ?

Thanks in advance!





Aucun commentaire:

Enregistrer un commentaire