Android12上无法在覆盖层下方点击或滚动。
创始人
2024-09-30 21:00:45
0

在Android 12上,系统实施了安全性更高的UI变更,因此无法在覆盖层下方进行点击或滚动。为了解决这个问题,您可以尝试以下两种方法:

方法一:使用WindowInsets

您可以使用WindowInsets API来监听窗口的insets,并将其应用于您的View,以确保其正确处理覆盖层。如下所示:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { yourView.setWindowInsetsAnimationCallback(new WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) { @Override public WindowInsets onProgress(WindowInsets insets, List runningAnimations) { // Get the top inset of the current window from WindowInsetsCompat. // This method is needed to work around an issue where WindowInsets.getInsets() returns null. Insets windowInsets = ViewCompat.getRootWindowInsets(yourView).getInsets(WindowInsetsCompat.Type.navigationBars()); int topInset = windowInsets.top;

        // Set top padding of yourView to the top inset of the window.
        yourView.setPadding(0, topInset, 0, 0);

        // Return the same insets to prevent changes to the view hierarchy.
        return insets;
    }
});

}

方法二:使用setOnApplyWindowInsetsListener

另一种方法是使用setOnApplyWindowInsetsListener来监听窗口的insets,并在View中应用它们。如下所示:

ViewCompat.setOnApplyWindowInsetsListener(yourView, new OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { // Get the top inset of the current window from WindowInsetsCompat. Insets windowInsets = insets.getInsets(WindowInsetsCompat.Type.navigationBars()); int topInset = windowInsets.top;

    // Set top padding of yourView to the top inset of the window.
    yourView.setPadding(0, topInset, 0, 0);

    // Return the modified insets to consume them.
    return insets.consumeSystemWindowInsets();
}

});

请注意,这些解决方法可能需要对您的代码进行一些更改。这些解决方案中提供的例子将根据需要调整窗口的padding,但是您可以根据您的应用程序需要进行调整。

相关内容

热门资讯

事发当天!上饶辅助设备出租,真... 事发当天!上饶辅助设备出租,真是是真的辅助工具(有挂头条)-哔哩哔哩上饶辅助设备出租脚本下载中分为三...
随着!菠萝神辅助器app,一直... 随着!菠萝神辅助器app,一直是有辅助平台(有挂教程)-哔哩哔哩1、很好的工具软件,可以解锁游戏的菠...
推出新举措!兴动海满辅助,一贯... 您好,兴动海满辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在...
做出回应!微乐贵阳捉鸡麻将挂软... 做出回应!微乐贵阳捉鸡麻将挂软件,果然真的是有辅助神器(有挂秘诀)-哔哩哔哩1、打开软件启动之后找到...
反观!九游破解辅助插件,都是真... 反观!九游破解辅助插件,都是真的有辅助神器(有挂秘籍)-哔哩哔哩九游破解辅助插件能透视中分为三种模型...
据文件显示!科米台州麻将辅助,... 据文件显示!科米台州麻将辅助,真是有挂辅助app(竟然有挂)-哔哩哔哩1、每一步都需要思考,不同水平...
今天上午!赣湘互娱挂,总是是有... 今天上午!赣湘互娱挂,总是是有辅助修改器(有挂详情)-哔哩哔哩1、在赣湘互娱挂插件功能辅助器技巧中,...
来临!广西友乐解码器辅助器,原... 来临!广西友乐解码器辅助器,原来真的是有辅助脚本(真的有挂)-哔哩哔哩1.广西友乐解码器辅助器 选牌...
来临!新天道辅助脚本,确实有挂... 来临!新天道辅助脚本,确实有挂辅助下载(有挂秘诀)-哔哩哔哩1、金币登录送、破产送、升级送、活动送。...
近期!青橙竞技卡五星辅助,好像... 近期!青橙竞技卡五星辅助,好像真的是有辅助脚本(竟然有挂)-哔哩哔哩1、用户打开应用后不用登录就可以...