无法在Android Pie中在键盘视图之外显示弹出窗口

14

我正在制作一个可以显示语言popupWindow的键盘。在所有设备上,我都可以得到完美的popupWindow,但是在只有Android Pie的设备上,我无法在键盘之外显示popupWindow

当蓝牙键盘连接时,我希望将popup显示在键盘的candidateView之外。

我正在使用这段代码:

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

有人知道问题出在哪里吗?

这是演示应用程序- https://github.com/priyankagb/andoidpiepopupwindowdemo

请看屏幕截图,

在 Android Pie 中,您可以看到底部有一个小线条,这是语言的 popupWindow

左边是 Pie 以下版本,右边是 Pie。


你尝试过使用 setWidth()setHeight() 方法手动设置弹出窗口的宽度和高度吗? - Syed Ahmed Jamil
是的,我尝试过了,但没有结果。 - Priyanka
从外观上看,弹出窗口似乎一开始就没有膨胀。因为如果它在键盘后面,我们仍然可以看到其中的一些内容,对吧? - Syed Ahmed Jamil
您可以在饼图下方的标志(小白线)下看到弹出窗口,但在下面的饼图中,弹出窗口会自动设置其位置在上方,但在Android Pie中不会发生这种情况。 - Priyanka
2
@PhanVanLinh,我已经创建了一个演示应用程序,请查看此链接。https://github.com/priyankagb/andoidpiepopupwindowdemo - Priyanka
显示剩余17条评论
2个回答

3
是的,我通过更改键盘布局文件解决了我的问题。
我在候选视图上面添加了一个虚拟视图。
就像这样...
<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,popup 将显示在这个区域内。

这个虚拟视图可以允许触摸访问背景视图,所以对于用户来说不可见。

参考链接 - https://dev59.com/hlQJ5IYBdhLWcg3w3p3z#53326786


0
请在弹出窗口显示的位置添加以下代码:
[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]

谢谢回答,但对我没用,我已经正确地显示了弹出窗口在上方和下方。问题是为什么在Android Pie中无法将弹出窗口显示在键盘之外。 - Priyanka

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接