Search code examples
androidpopupwindowandroid-9.0-pie

Can not show popup window out of the keyboard view in Android Pie


I am making a Keyboard which shows a popupWindow of languages. In all device, I get perfect popupWindow outside of keyboard but in only Android Pie, I can not show popupWindow outside of the keyboard.

I want to show popup outside of keyboard's candidateView when Bluetooth keyboard is connected.

I am using this code

setClippingEnabled(false);
showAtLocation(anchor, Gravity.NO_GRAVITY, x, y);

Does someone have any idea, what is the issue?

here is demo app - https://github.com/priyankagb/andoidpiepopupwindowdemo

see screenshots,

In Android Pie in which you can see a small line at the bottom which is popupWindow for languages

Left is Below Pie, Right is Pie


Solution

  • Yes, I have solved my issue by changing my keyboard's layout file

    I have added one dummy view above candidate view

    like...

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <View
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toTopOf="@+id/rlPredictionView" />
    
        <RelativeLayout
            android:id="@+id/rlPredictionView"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@drawable/background_with_shadow_prediction_bar"
            android:visibility="visible"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent">
    
            ...
    
        </RelativeLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    than override this method in InputMethodService class

     @Override
        public void onComputeInsets(InputMethodService.Insets outInsets) {
            super.onComputeInsets(outInsets);
            outInsets.visibleTopInsets = candidateView.getRelativeView().getTop();
            outInsets.contentTopInsets = candidateView.getRelativeView().getTop();
        }
    

    dummy view above rlPredictionView will set visibleTopInsets of the keyboard and in this area, the popup will show

    this dummy view will allow accessing background view on touch so this will not visible to the user

    Reference - https://stackoverflow.com/a/53326786/10989990