Android 安卓:键盘上方的晶圆厂与系统\用户界面\标志\布局\全屏标志相结合

Android 安卓:键盘上方的晶圆厂与系统\用户界面\标志\布局\全屏标志相结合,android,keyboard,fullscreen,floating-action-button,flags,Android,Keyboard,Fullscreen,Floating Action Button,Flags,问题在于,使用此标志时,FAB不会停留在键盘上方: this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); 我试过: android:fitsSystemWindows="true" 它可以工作,但会删除系统界面标志布局全屏效果 android:windowSoftInputMode="adjustResize" 它不起作用 this.getWindow().

问题在于,使用此标志时,FAB不会停留在键盘上方:

this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
我试过:

android:fitsSystemWindows="true"
它可以工作,但会删除系统界面标志布局全屏效果

android:windowSoftInputMode="adjustResize"
它不起作用

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
它也不起作用


有什么建议吗?

如果您使用的是系统UI方法(),我刚刚找到了一个简单可靠的解决方案

当您使用View.SYSTEM\u UI\u FLAG\u LAYOUT\u全屏显示时,例如,如果您使用CoordinatorLayout,则此选项适用

它不适用于WindowManager.LayoutParams.FLAG_FULLSCREEN(您也可以在android主题中设置:windowFullscreen),但您可以使用SYSTEM_UI_FLAG_LAYOUT_STABLE(根据文档,“具有相同的视觉效果”)实现类似的效果,并且此解决方案应该可以再次工作

getWindow().getDecorView().SetSystemMivibility(视图.SYSTEM\u UI\u标志\u全屏 |View.SYSTEM\u UI\u FLAG\u HIDE\u NAVIGATION/*如果要隐藏导航*/ |View.SYSTEM_UI_FLAG_LAYOUT_全屏| View.SYSTEM_UI_FLAG_LAYOUT_稳定)

我已经在运行棉花糖的设备上测试过了

关键是,软键盘也是系统窗口之一(如状态栏和导航栏),因此系统发送的WindowInset包含准确可靠的信息

对于在抽屉布局中试图在状态栏后面绘制的用例,我们可以创建一个只忽略顶部插入的布局,并应用说明软键盘的底部插入

以下是我的自定义框架布局:

/**
 * Implements an effect similar to {@code android:fitsSystemWindows="true"} on Lollipop or higher,
 * except ignoring the top system window inset. {@code android:fitsSystemWindows="true"} does not
 * and should not be set on this layout.
 */
public class FitsSystemWindowsExceptTopFrameLayout extends FrameLayout {

    public FitsSystemWindowsExceptTopFrameLayout(Context context) {
        super(context);
    }

    public FitsSystemWindowsExceptTopFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FitsSystemWindowsExceptTopFrameLayout(Context context, AttributeSet attrs,
                                                 int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    public FitsSystemWindowsExceptTopFrameLayout(Context context, AttributeSet attrs,
                                                 int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setPadding(insets.getSystemWindowInsetLeft(), 0, insets.getSystemWindowInsetRight(),
                    insets.getSystemWindowInsetBottom());
            return insets.replaceSystemWindowInsets(0, insets.getSystemWindowInsetTop(), 0, 0);
        } else {
            return super.onApplyWindowInsets(insets);
        }
    }
}
使用它:

<com.example.yourapplication.FitsSystemWindowsExceptTopFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Your original layout here -->
</com.example.yourapplication.FitsSystemWindowsExceptTopFrameLayout>

学分分配给: