Не удается отобразить всплывающее окно из вида клавиатуры в Android Pie - программирование

Не удается отобразить всплывающее окно из вида клавиатуры в Android Pie

Я делаю клавиатуру, которая показывает popupWindow языков. На всех устройствах я получаю идеальное popupWindow за пределами клавиатуры, но только в Android Pie я не могу показать popupWindow за пределами клавиатуры.

Я хочу, чтобы показать всплывающее окно вне клавиатуры candidateView когда Bluetooth клавиатура подключена.

Я использую этот код

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

У кого-нибудь есть идеи, в чем проблема?

Вот демо-приложение - https://github.com/priyankagb/andoidpiepopupwindowdemo

смотреть скриншоты,

В Android Pie, в котором вы можете увидеть небольшую линию внизу, которая является popupWindow для языков

Слева - пирог, справа - пирог

9yOG0.pngVusiP.png

4b9b3361

Ответ 1

Да, я решил проблему, изменив файл раскладки клавиатуры

Я добавил один фиктивный вид над кандидатом

лайк...

<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>

чем переопределить этот метод в классе InputMethodService

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

фиктивное представление выше rlPredictionView установит visibleTopInsets клавиатуры, и в этой области всплывающее окно покажет

этот фиктивный вид позволит получить доступ к фоновому виду на ощупь, поэтому он не будет виден пользователю

Ссылка - fooobar.com/questions/16457717/...

Ответ 2

Добавьте следующий код, где будет отображаться ваше всплывающее окно

[view].getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){
            public void onGlobalLayout(){
                int screenHeight = [view].getRootView().getHeight();
                Rect r = new Rect();
                View view = getWindow().getDecorView();
                view.getWindowVisibleDisplayFrame(r);
                int keyBoardHeight = screenHeight - r.bottom;
                if ( keyBoardHeight > 150 ){
                    // keyboard is showing, set popup window above keyboard height
                } else {
                    // keyboard gone, restore popup window location to center screen
                }
            }
        });

Замените [view] вашими взглядами