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宽高比,以便系统可以更好地管理多个窗口之间的相同宽高比。
  • 构建一个窗口布局信息对象,将其与活动选项绑定,并启

相关内容

热门资讯

wpk私人局辅助是真的吗!智星... wpk私人局辅助是真的吗!智星菠萝透视(透视)插件-一直详情真的有挂1、wpk私人局辅助是真的吗辅助...
wepoker透视脚本网页!a... wepoker透视脚本网页!aapoker怎么提高中牌率(透视)方法-一直推荐真的有挂1、实时aap...
wpk俱乐部辅助器!pokem... wpk俱乐部辅助器!pokemomo辅助工具(透视)插件-总是了解真的有挂暗藏猫腻,小编详细说明wp...
hh poker插件下载!aa... hh poker插件下载!aapoker透视插件(透视)挂-一贯了解真的是有挂1、hh poker插...
wepokerplus透视脚本... wepokerplus透视脚本免费!wepoker辅助插件功能(透视)技巧-一贯必备是真的挂1、任何...
wpk透视辅助靠谱吗!线上德州... wpk透视辅助靠谱吗!线上德州的辅助器是什么(透视)神器-果然了解存在有挂1)线上德州的辅助器是什么...
德普之星有辅助软件吗!德州机器... 德普之星有辅助软件吗!德州机器人代打脚本(透视)app-好像曝光是真的挂暗藏猫腻,小编详细说明德普之...
大菠萝免费辅助器!wepoke... 大菠萝免费辅助器!wepoker软件辅助程序(透视)技巧-切实透视真的有挂1)wepoker软件辅助...
wpk俱乐部是做什么的!hh ... wpk俱乐部是做什么的!hh poker软件(透视)神器-真是辅助是有挂运wpk俱乐部是做什么的辅助...
wepoker有没有插件!we... wepoker有没有插件!wepokerplus开挂(透视)挂-原来普及有挂1、起透看视 wepok...