Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 838
Priyanka Avatar asked Jul 04 '19 11:07

Priyanka


People also ask

What is display pop up window Android?

android.widget.PopupWindow. This class represents a popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity.

How do I get my Android screen to pop up at the top?

To display the popup window above the view, you can use the showAsDropDown() function. With: v: View(Anchor)


1 Answers

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

like image 71
Priyanka Avatar answered Oct 18 '22 10:10

Priyanka