Android11上的多窗口模式+
创始人
2024-08-20 11:30:05
0

Android 11引入了新的多窗口模式增强功能,允许用户将应用程序分割成多个窗口同时运行。这个新的功能需要在代码中进行一些调整,在此提供一个简单的代码示例以启发实现。

为了支持多窗口,需要在应用程序的活动中添加以下代码片段:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { 
    getWindow().setDecorFitsSystemWindows(false); 
    final WindowMetrics windowMetrics = getWindowManager().getCurrentWindowMetrics(); 
    final Insets insets = windowMetrics.getWindowInsets().getInsetsIgnoringVisibility(WindowInsets.Type.systemBars()); 
    final int insetsWidth = insets.left + insets.right; 
    final int insetsHeight = insets.top + insets.bottom; 

    final Rect bounds = windowMetrics.getBounds(); 
    bounds.inset(insets); 
    final int width = bounds.width(); 
    final int height = bounds.height(); 

    final Rational aspectRatio = new Rational(width, height); 
    final Pair pair = new Pair<>( 
        WindowLayoutInfo.Builder.from(getWindow(), null).setBounds(bounds).setForegroundInsets(insets).setSystemGestureInsets(insets).setTrustedOverlay(true).build(), 
        ActivityOptions.makeBasic().setLaunchWindowingMode(SCREEN_SPLIT_SECONDARY).setTaskAlwaysOnTop(true).setTaskWindowingMode(SPLIT_SCREEN_CREATED).setActivityLaunchAnimation(NO_ANIMATION) 
    ); 

    getWindow().setWindowLayoutInfo(pair.first); 
    startActivity(getApplicationInfo().packageName, MainActivity.class, null, pair.second.toBundle()); 
    finish(); 
}

这个代码片段做了很多事情,包括:

  • 获取窗口度量,并计算中心窗口的边界和偏移量。
  • 创建一个rationale宽高比,以便系统可以更好地管理多个窗口之间的相同宽高比。
  • 构建一个窗口布局信息对象,将其与活动选项绑定,并启

相关内容

热门资讯

2026版教程!wepoker... 2026版教程!wepoker怎么拿到好牌,德普辅助软件,真是是有挂(有挂解惑)1、起透看视 德普辅...
为切实保障!wepoker辅助... 为切实保障!wepoker辅助真的假的,德扑之星辅助工具如何打开,总是真的有挂(有挂技巧)一、德扑之...
据相关数据显示!sohoo p... 据相关数据显示!sohoo poker辅助,德普之星私人局辅助器,一直存在有挂(有挂方略)1、德普之...
据报道!wepoker私人局有... 据报道!wepoker私人局有透视吗,智星德州有脚本吗,原来确实有挂(有挂教学)1、下载好智星德州有...
此事引发网友热议!hh pok... 此事引发网友热议!hh poker辅助有用吗,德普之星辅助软件,切实存在有挂(确实有挂)1、进入游戏...
代打辅助挂!wepoker游戏... 代打辅助挂!wepoker游戏的安装教程,德普之星透视,竟然是真的有挂(有挂透明挂)1、在德普之星透...
第三方技巧!sohoopoke... 第三方技巧!sohoopoker辅助,德扑之星透视辅助软件激活码,果然确实有挂(真的有挂)1、玩家可...
此事备受玩家关注!wepoke... 此事备受玩家关注!wepoker透视辅助下载,德普之星辅助器,原来存在有挂(有挂细节)1、每一步都需...
第三方技巧!xpoker辅助,... 第三方技巧!xpoker辅助,如何下载德普之星辅助软件,切实是有挂(有挂解密)1、上手简单,内置详细...
目前来看!wepoker私人局... 目前来看!wepoker私人局辅助器怎么用,德普之星辅助器怎么用,真是真的有挂(有人有挂)德普之星辅...