Skip to content

ContentView

ContentView is an extension function of ComponentActivity in the :compose Android module. It serves as the entry point where the application's root Compose interface is injected.

Characteristics

  • Not a standard @Composable: This function is equivalent to setContent {}. Therefore, it is called once during onCreate() in the Activity.
  • Built-In Edge-to-Edge: Directly calls enableEdgeToEdge() so the content spans across System Bars and Navigation Bars.
  • Auto Theme Wrapping: This function wraps its content in Theme directly to execute Dependency Injection for Design Tokens.
  • Page Overscroll: The page content bounces when dragged past its edge, even when it does not scroll. The AppBar stays pinned. A ScrollView whose content overflows bounces on its own instead, so the page never bounces twice. One whose content fits leaves the drag to the page. Controls that track their own drags, such as Slider, do not move the page. Turn it off for the whole app with overscroll = false.
  • Glass Backdrop: The page is the background of a GlassLayer and the AppBar floats over it, so glass in the AppBar blurs the content that scrolls under it.
  • Status Bar Layering: It uses the highest Compose z-index to render the statusBarColor, ensuring it remains visible even if you render a header (e.g. AppBar) that overlaps into the status bar insets.

API Reference

@OptIn(ExperimentalComponentsApi::class)
fun ComponentActivity.ContentView(
    themeMode: () -> ThemeMode = { ThemeMode.Auto },
    statusBarIconMode: () -> StatusBarIconMode = { StatusBarIconMode.Auto },
    statusBarColor: () -> Color = { Color.Transparent },
    palette: Palette? = null,
    typography: Typography = DefaultTypography,
    fontFamily: FontFamily? = null,
    sizeToken: SizeToken = SizeToken.Medium,
    dynamicColor: Boolean = false,
    overscroll: Boolean = true,
    appBar: (@Composable () -> Unit)? = null,
    content: @Composable () -> Unit,
)

enum class StatusBarIconMode {
    Light,
    Dark,
    Auto,
}

enum class ThemeMode {
    Light,
    Dark,
    Auto,
}

Parameters

Name Data Type Description
themeMode (() -> ThemeMode)? = null -> ThemeMode.Auto Sets the theme (Light, Dark, or follows the system via Auto). A change crossfades from the old theme to the new one. Default: Auto.
statusBarIconMode (() -> StatusBarIconMode)? = null -> StatusBarIconMode.Auto Determines the icon color (battery, clock, signal). There is an Auto mode that mathematically calculates the luminance score from statusBarColor.
statusBarColor (() -> Color)? = null -> Color.Transparent The color of the status bar. It is recommended to match this with the AppBar color.
palette Palette? Allows developers to override colors. If null, it will automatically follow themeMode.
typography (() -> Typography)? = null -> DefaultTypography Override the design's typography scale. Default: DefaultTypography.
fontFamily FontFamily? Custom font family applied globally to all Text components. If null, uses Inter, which ships with CortenaUI. Pass FontFamily.Default for the system font.
dynamicColor (Experimental) Boolean Provides the dynamic color feature (Material You). Not fully implemented yet, currently only gives a warning in Logcat.
overscroll Boolean = true When true, the page bounces when dragged past its edge, even if nothing on it scrolls. false turns it off app-wide.
appBar (@Composable () -> Unit)? = null A dedicated layout slot for the AppBar. Fills the slot provided in the topmost Column.
content @Composable () -> Unit The main content slot of your application (e.g., Body).