通过按钮添加画中画
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如需通过点击按钮进入画中画模式,请对 findActivity()
调用 enterPictureInPictureMode()
。
这些参数已通过之前对 PictureInPictureParams.Builder
的调用设置,因此您无需在构建器上设置新参数。不过,如果您确实想在点击按钮时更改任何参数,可以在此处进行设置。
val context = LocalContext.current
Button(onClick = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.findActivity().enterPictureInPictureMode(
PictureInPictureParams.Builder().build()
)
} else {
Log.i(PIP_TAG, "API does not support PiP")
}
}) {
Text(text = "Enter PiP mode!")
}
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-24。
[null,null,["最后更新时间 (UTC):2025-08-24。"],[],[],null,["# Add PiP through a button\n\nTo enter PiP mode through a button click, call\n[`enterPictureInPictureMode()`](/reference/android/app/Activity#enterPictureInPictureMode(android.app.PictureInPictureParams)) on `findActivity()`.\n\nThe parameters are already set by previous calls to the\n[`PictureInPictureParams.Builder`](/reference/android/app/Activity#enterPictureInPictureMode(android.app.PictureInPictureParams)), so you do not need to set new parameters\non the builder. However, if you do want to change any parameters on button\nclick, you can set them here.\n\n\n```kotlin\nval context = LocalContext.current\nButton(onClick = {\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.O) {\n context.findActivity().enterPictureInPictureMode(\n PictureInPictureParams.Builder().build()\n )\n } else {\n Log.i(PIP_TAG, \"API does not support PiP\")\n }\n}) {\n Text(text = \"Enter PiP mode!\")\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/pictureinpicture/PictureInPictureSnippets.kt#L103-L114\n```\n\n\u003cbr /\u003e"]]