קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
אחרי שהאפליקציה מטרגטת ל-SDK 35 ומעלה, התצוגה מקצה לקצה נאכפת. סרגל הסטטוס של המערכת וסרגלי הניווט באמצעות תנועות הם שקופים, אבל סרגל הניווט באמצעות שלושה כפתורים הוא שקוף למחצה. כדי להגדיר את המינוי כתואם לדור הקודם, צריך להתקשר למספר enableEdgeToEdge.
כדי ליצור סרגל ניווט שקוף באמצעות מחוות, צריך לטרגט ל-Android מגרסה 15 ואילך או להפעיל את enableEdgeToEdge() עם ארגומנטים שמוגדרים כברירת מחדל לגרסאות קודמות. בסרגל הניווט עם שלושת הלחצנים, מגדירים את Window.setNavigationBarContrastEnforced לערך false. אחרת, יוחל מסך חצי שקוף.
יצירת סרגלי מערכת שקופים
כדי ליצור סרגל סטטוס שקוף למחצה, יוצרים פונקציה מותאמת אישית שאפשר להרכיב ממנה רכיבים, שחופפת לתוכן הראשי ומציירת מעבר צבעים באזור שמכוסה על ידי שוליים פנימיים.
classSystemBarProtectionSnippets:ComponentActivity(){overridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState)// enableEdgeToEdge sets window.isNavigationBarContrastEnforced = true// which is used to add a translucent scrim to three-button navigationenableEdgeToEdge()setContent{MyTheme{// Main contentMyContent()// After drawing main content, draw status bar protectionStatusBarProtection()}}}}@ComposableprivatefunStatusBarProtection(color:Color=MaterialTheme.colorScheme.surfaceContainer,heightProvider:()->Float=calculateGradientHeight(),){Canvas(Modifier.fillMaxSize()){valcalculatedHeight=heightProvider()valgradient=Brush.verticalGradient(colors=listOf(color.copy(alpha=1f),color.copy(alpha=.8f),Color.Transparent),startY=0f,endY=calculatedHeight)drawRect(brush=gradient,size=Size(size.width,calculatedHeight),)}}@ComposablefuncalculateGradientHeight():()->Float{valstatusBars=WindowInsets.statusBarsvaldensity=LocalDensity.currentreturn{statusBars.getTop(density).times(1.2f)}}
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-27 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-08-27 (שעון UTC)."],[],[],null,["# About system bar protection\n\nOnce your app targets SDK 35 or later, [edge-to-edge is enforced](/about/versions/15/behavior-changes-15#edge-to-edge). The\nsystem status bar and gesture navigation bars are transparent, but the\nthree-button navigation bar is translucent. Call `enableEdgeToEdge` to make this\nbackwards compatible.\n\nHowever, the system defaults might not work for all use cases. Consult the\n[Android system bars design guidance](/design/ui/mobile/guides/foundations/system-bars) and [edge-to-edge design\nguidance](/design/ui/mobile/guides/layout-and-content/edge-to-edge) for an overview of when to consider having transparent or\ntranslucent system bars.\n\nCreate transparent system bars\n------------------------------\n\nCreate a transparent gesture navigation bar by targeting Android 15 or later or\nby calling `enableEdgeToEdge()` with default arguments for earlier versions. For\nthree-button navigation bar, set [`Window.setNavigationBarContrastEnforced`](/reference/android/view/Window#setNavigationBarContrastEnforced(boolean))\nto `false` otherwise there will be a translucent scrim applied.\n\nCreate translucent system bars\n------------------------------\n\nTo create a translucent status bar, create a custom composable that overlaps the\nmain content and draws a gradient in the area covered by insets.\n\n\n```kotlin\nclass SystemBarProtectionSnippets : ComponentActivity() {\n\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n\n // enableEdgeToEdge sets window.isNavigationBarContrastEnforced = true\n // which is used to add a translucent scrim to three-button navigation\n enableEdgeToEdge()\n\n setContent {\n MyTheme {\n // Main content\n MyContent()\n\n // After drawing main content, draw status bar protection\n StatusBarProtection()\n }\n }\n }\n}\n\n@Composable\nprivate fun StatusBarProtection(\n color: Color = MaterialTheme.colorScheme.surfaceContainer,\n heightProvider: () -\u003e Float = calculateGradientHeight(),\n) {\n\n Canvas(Modifier.fillMaxSize()) {\n val calculatedHeight = heightProvider()\n val gradient = Brush.verticalGradient(\n colors = listOf(\n color.copy(alpha = 1f),\n color.copy(alpha = .8f),\n Color.Transparent\n ),\n startY = 0f,\n endY = calculatedHeight\n )\n drawRect(\n brush = gradient,\n size = Size(size.width, calculatedHeight),\n )\n }\n}\n\n@Composable\nfun calculateGradientHeight(): () -\u003e Float {\n val statusBars = WindowInsets.statusBars\n val density = LocalDensity.current\n return { statusBars.getTop(density).times(1.2f) }\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/layouts/SystemBarProtectionSnippets.kt#L53-L103\n```\n\n\u003cbr /\u003e\n\n**Figure 1.** A translucent status bar.\n\nFor adaptive apps, insert a custom composable that matches the colors of each\npane, as seen in the [Edge-to--edge design](/design/ui/mobile/guides/layout-and-content/edge-to-edge). To create a translucent\nnavigation bar, set [`Window.setNavigationBarContrastEnforced`](/reference/android/view/Window#setNavigationBarContrastEnforced(boolean)) to true."]]