הוספת 'תמונה בתוך תמונה' באמצעות לחצן
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כדי לעבור למצב 'תמונה בתוך תמונה' בלחיצה על לחצן, מתקשרים למספר enterPictureInPictureMode()
ב-findActivity()
.
הפרמטרים כבר מוגדרים על ידי קריאות קודמות ל-PictureInPictureParams.Builder
, כך שאין צורך להגדיר פרמטרים חדשים ב-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 (שעון UTC).
[null,null,["עדכון אחרון: 2025-08-24 (שעון UTC)."],[],[],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"]]