How do I maintain the Immersive Mode in Spinner?

后端 未结 2 1541
眼角桃花
眼角桃花 2020-12-09 22:32

I use immersive-sticky mode to hide the navigation bar and action bar:

@TargetApi(19)
private void setImmersiveMode() {
    if (Build.VERSION.SDK_INT >= 1         


        
2条回答
  •  失恋的感觉
    2020-12-09 23:30

    For everyone who, like me, will start rewriting solution pasted by @Quinn from Kotlin to Java and later they will find out that on the linked git repo is the solution in Java also, I am pasting it here:

    import android.widget.ListPopupWindow;
    import android.widget.PopupWindow;
    import android.widget.Spinner;
    
    public static void avoidSpinnerDropdownFocus(Spinner spinner) {
        try {
            Field listPopupField = Spinner.class.getDeclaredField("mPopup");
            listPopupField.setAccessible(true);
            Object listPopup = listPopupField.get(spinner);
            if (listPopup instanceof ListPopupWindow) {
                Field popupField = ListPopupWindow.class.getDeclaredField("mPopup");
                popupField.setAccessible(true);
                Object popup = popupField.get((ListPopupWindow) listPopup);
                if (popup instanceof PopupWindow) {
                    ((PopupWindow) popup).setFocusable(false);
                }
            }
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    

提交回复
热议问题