Android IME浮动视图

问题描述

我正在尝试创建具有混合结果的浮动键盘。我为Android车载主机创建了一种“特殊类型”的键盘,可以通过车载控制器进行操作。在大多数情况下,它都可以正常工作,但是在某些应用中,它会立即关闭。问题出在我对浮动视图(或缺乏浮动视图)的实现上。我对具有可拖动窗口不感兴趣,我为键盘提供了3个预定义的位置,足以容纳车载显示器。我的键盘通常浮动在任何其他视图上方,但是在某些应用程序中,它会将输入字段向上推(换句话说,应用程序会重新缩放/重新调整以显示IME),这告诉我这不是正确的浮动视图。

这是一个演示https://youtu.be/9_KUtrIRXhM

这是我的InputMethodService的一部分,我在其中处理显示键盘的窗口。

    @Override
    public void onConfigureWindow(Window win,boolean isFullscreen,boolean isCandidatesOnly) {
        if (this.getwindow().getwindow() != null) {
            keyboardParams = getwindow().getwindow().getAttributes();
            float factor = win.getContext().getResources().getdisplayMetrics().density;
            keyboardParams.x = mySettingsManager.rotaryX;
            keyboardParams.y = 0;
            keyboardParams.width = (int) (430 * factor);
            keyboardParams.height = (int) (430 * factor);
            keyboardParams.alpha = mySettingsManager.rotaryT;
            keyboardParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
            getwindow().getwindow().setAttributes(keyboardParams);
        }
    }

这是布局本身。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/roundKeyboard"
    android:layout_width="430dp"
    android:layout_height="430dp"
    android:layout_gravity="bottom">

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintEnd_toStartOf="@+id/btn_wheel"
        app:layout_constraintStart_toStartOf="@+id/btn_wheel" >

        <Button
            android:id="@+id/btn_wheel"
            android:layout_width="430dp"
            android:layout_height="430dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:background="@drawable/btn_down"
            android:clickable="true"
            android:longClickable="true"
            android:focusable="false"
            android:fontFamily="@font/bmw"
            android:textAlignment="center"
            android:textColor="@color/font_color"
            android:textSize="100sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

        <Button
            android:id="@+id/highlight"
            android:layout_width="430dp"
            android:layout_height="430dp"
            android:background="@drawable/highlight"
            android:clickable="false"
            android:focusable="false"
            android:rotation="221"
            app:layout_constraintBottom_toBottomOf="@+id/btn_wheel"
            app:layout_constraintEnd_toEndOf="@+id/btn_wheel" />

        ...

    </androidx.constraintlayout.widget.ConstraintLayout>

</FrameLayout>

就像我说的那样,它确实起作用了……但是有时候它只是拒绝合作。这是我的一名测试人员https://streamable.com/tlg8ap

发送给我的视频

我已经尝试寻找解决此问题已有相当一段时间了。如果有人能指出正确的方向,我将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)