透過按鈕新增子母畫面
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如要透過按一下按鈕進入 PiP 模式,請在 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 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-24 (世界標準時間)。
[null,null,["上次更新時間: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"]]