0Pricing
Jetpack Compose Academy · درس

‏setContent: حيث تبدأ واجهة المستخدم

اربط شجرة Composable بـ Activity

‏setContent: حيث تبدأ واجهة المستخدم درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Connecting Compose to Android

Your Composables need a home. The setContent call inside an Activity is the bridge that hands your UI tree to the Android screen. 🔗

Inside onCreate

You call setContent from an Activity onCreate. That is the moment Android tells your app it is time to show a screen.

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent { Greeting() }
}

It Takes a Lambda

setContent accepts a lambda, and inside that block you call your Composables. Everything in the braces becomes the screen content.

setContent {
    Greeting("Compose")
}

The Lambda Is Composable

That lambda is itself a @Composable scope. So you can call any Composable directly inside it, no extra setup required.

One Root Composable

A clean app calls a single root Composable here, often your whole app or theme, which then nests everything else below it.

setContent {
    MyApp()
}

Wrap in Your Theme

Most apps wrap the root in their theme so colors and fonts apply everywhere. The theme is just another Composable around your UI.

setContent {
    MyAppTheme {
        MyApp()
    }
}

Replaces setContentView

In the old View system you called setContentView with an XML layout. Compose swaps that for setContent with a Composable lambda.

Extends ComponentActivity

The Activity that uses setContent typically extends ComponentActivity, the lightweight base class Compose is designed to work with.

class MainActivity : ComponentActivity() {
    // onCreate with setContent
}

Where the Tree Mounts

setContent is the entry point. From here Compose builds, lays out, and draws the whole tree of Composables you call inside it.

Add Surface for Background

Wrapping content in a Surface gives a themed background and elevation, a common first child under your theme.

setContent {
    MyAppTheme {
        Surface { MyApp() }
    }
}

One setContent Per Screen

You normally call setContent once per Activity. To show different content, you change state inside the tree, not call setContent again.

Quick Check

A final check on where Compose UI starts.

Recap

You now know where it all begins: call setContent in onCreate, pass a Composable lambda, wrap it in your theme, and Compose draws your app. 🎉

الأسئلة الشائعة

هل درس «‏setContent: حيث تبدأ واجهة المستخدم» مجاني؟

نعم — نص درس «‏setContent: حيث تبدأ واجهة المستخدم» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.

ماذا ستتعلم في «‏setContent: حيث تبدأ واجهة المستخدم»؟

اربط شجرة Composable بـ Activity تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟

لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «‏setContent: حيث تبدأ واجهة المستخدم»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟

نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. كتابة دالة @Composable
  2. المعاينات المباشرة باستخدام @Preview
  3. استدعاء Composables من Composables
  4. ‏setContent: حيث تبدأ واجهة المستخدم
← العودة إلى Jetpack Compose Academy