欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > Android——画中画模式

Android——画中画模式

2025/2/24 19:01:29 来源:https://blog.csdn.net/weixin_45932565/article/details/143430564  浏览:    关键词:Android——画中画模式

应用中的画中画

  • 监听回到桌面与打开任务列表的广播
  • 收到广播之后,调用 enterPictureInPictureMode 方法进入画中画模式
  • 重写活动页面的 onPictureInPictureModeChanged 方法,补充进入画中画模式或退出画中画模式时的处理逻辑

回到桌面与切到任务列表

  • 按下主页键会回到桌面,按下任务键会打开任务列表,这两个操作并未提供相应的按键处理方法,而是通过广播发出时间信息。
  • 若想知晓是否回到桌面,以及是否打开任务列表,均需收听系统广播Intent.ACTION_CLOSE_SYSTEM_DIALOGS
  • 从收到的广播意图中获取原因reason字段,该字段值为 homekey 时表示回到桌面,值为 recentapps 时打开任务列表

清单文件中配置 supportsPictureInPicture

        <activityandroid:name=".ReturnDesktopActivity"android:supportsPictureInPicture="true"android:exported="true">
        receiver = new BroadcastReceiver() {@Overridepublic void onReceive(Context context, Intent intent) {if (intent != null && intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {String reason = intent.getStringExtra("reason");if (!reason.isEmpty() && (reason.equals("homekey") || reason.equals("recentapps"))) {// Android8.0开始才提供画中画模式if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isInPictureInPictureMode()) {PictureInPictureParams.Builder builder = new PictureInPictureParams.Builder();// 设置宽高比例值,第一个参数表示分子,第二个参数表示分母// 下面的10/5=2,表示画中画窗口的宽度是高度的两倍Rational ratio = new Rational(10, 5);builder.setAspectRatio(ratio);// 进入画中画模式enterPictureInPictureMode(builder.build());}}}}};

案例代码

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词