स्प्लैश स्क्रीन जोड़ना

अगर आपके ऐप्लिकेशन में कस्टम स्प्लैश स्क्रीन लागू की गई है या वह लॉन्चर थीम का इस्तेमाल करता है, तो अपने ऐप्लिकेशन को Jetpack में उपलब्ध SplashScreen लाइब्रेरी पर माइग्रेट करें. इससे यह पक्का किया जा सकेगा कि वह Wear OS के सभी वर्शन पर सही तरीके से दिखे.

इस पेज पर, स्प्लैश स्क्रीन को लागू करने के सिलसिलेवार निर्देश देखें. इससे आपको SplashScreen लाइब्रेरी का इस्तेमाल करके, स्प्लैश स्क्रीन जोड़ने का तरीका पता चलेगा. इससे यह भी पता चलेगा कि स्प्लैश स्क्रीन, डिज़ाइन से जुड़े दिशा-निर्देशों के मुताबिक है या नहीं.

डिपेंडेंसी जोड़ें

अपने ऐप्लिकेशन मॉड्यूल की build.gradle फ़ाइल में, यह डिपेंडेंसी जोड़ें:

Groovy

dependencies {
    implementation "androidx.core:core-splashscreen:1.2.0"
}

Kotlin

dependencies {
    implementation("androidx.core:core-splashscreen:1.2.0")
}

पक्का करें कि आपके पास वर्शन 1.0.1 या इसके बाद का वर्शन हो, ताकि आपको Wear OS के डिफ़ॉल्ट डाइमेंशन के लिए सहायता मिल सके.

कोई थीम जोड़ें

res/values/styles.xml में स्प्लैश स्क्रीन की थीम बनाएं. पैरंट एलिमेंट, आइकॉन के आकार पर निर्भर करता है:

  • अगर आइकॉन गोल है, तो Theme.SplashScreen का इस्तेमाल करें.
  • अगर आइकॉन का आकार अलग है, तो Theme.SplashScreen.IconBackground का इस्तेमाल करें.

बैकग्राउंड को काले रंग से भरने के लिए, windowSplashScreenBackground का इस्तेमाल करें. postSplashScreenTheme की वैल्यू को उस थीम पर सेट करें जिसका इस्तेमाल ऐक्टिविटी को करना चाहिए. साथ ही, windowSplashScreenAnimatedIcon को ड्रॉ करने लायक या ऐनिमेटेड ड्रॉ करने लायक पर सेट करें:

<resources>
    <style name="Theme.App" parent="@android:style/Theme.DeviceDefault" />

    <style name="Theme.App.Starting" parent="Theme.SplashScreen">
        <!-- Set the splash screen background to black -->
        <item name="windowSplashScreenBackground">@android:color/black</item>
        <!-- Use windowSplashScreenAnimatedIcon to add a drawable or an animated
             drawable. -->
        <item name="windowSplashScreenAnimatedIcon">@drawable/splash_screen</item>
        <!-- Set the theme of the Activity that follows your splash screen. -->
        <item name="postSplashScreenTheme">@style/Theme.App</item>
    </style>
</resources>

अगर आपने गोल आइकॉन का इस्तेमाल नहीं किया है, तो आपको अपने आइकॉन के नीचे सफ़ेद बैकग्राउंड सेट करना होगा. इस मामले में, Theme.SplashScreen.IconBackground को पैरंट थीम के तौर पर इस्तेमाल करें और windowSplashScreenIconBackgroundColor एट्रिब्यूट को सेट करें:

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
    <!-- Set a white background behind the splash screen icon. -->
    <item name="windowSplashScreenIconBackgroundColor">@android:color/white</item>
</style>

अन्य एट्रिब्यूट ज़रूरी नहीं हैं.

थीम के लिए ड्रॉएबल बनाना

स्प्लैश स्क्रीन की थीम के लिए, windowSplashScreenAnimatedIcon एट्रिब्यूट में ड्रॉ करने लायक ऑब्जेक्ट पास करना ज़रूरी है. उदाहरण के लिए, इसे बनाने के लिए नई फ़ाइल res/drawable/splash_screen.xml जोड़ें. साथ ही, ऐप्लिकेशन लॉन्चर आइकॉन और स्प्लैश स्क्रीन आइकॉन के सही साइज़ का इस्तेमाल करें:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:width="@dimen/splash_screen_icon_size"
        android:height="@dimen/splash_screen_icon_size"
        android:drawable="@mipmap/ic_launcher"
        android:gravity="center" />
</layer-list>

स्प्लैश स्क्रीन के आइकॉन का साइज़, res/values/dimens.xml में तय किया जाता है. यह इस बात पर निर्भर करता है कि आइकॉन गोल है या नहीं:

<resources>
    <!-- Round app icon can take all of default space -->
    <dimen name="splash_screen_icon_size">48dp</dimen>
</resources>

...या गोल नहीं है और इसलिए, आइकॉन के बैकग्राउंड का इस्तेमाल करना ज़रूरी है:

<resources>
    <!-- Non-round icon with background must use reduced size to fit circle -->
    <dimen name="splash_screen_icon_size">36dp</dimen>
</resources>

थीम तय करें

अपने ऐप्लिकेशन की मेनिफ़ेस्ट फ़ाइल (AndroidManifest.xml) में, शुरुआती गतिविधि की थीम को बदलें. आम तौर पर, ये वे थीम होती हैं जो लॉन्चर आइटम को तय करती हैं या जिन्हें एक्सपोर्ट किया जाता है. इन्हें पिछले चरण में बनाई गई थीम से बदलें:

<activity
    android:name=".snippets.SplashScreenActivity"
    android:exported="true"
    android:taskAffinity=""
    android:theme="@style/Theme.App.Starting">
    <!-- ... -->
</activity>

शुरुआती गतिविधि अपडेट करना

super.onCreate() को कॉल करने और कंपोज़ेबल को लोड करने से पहले, शुरुआती गतिविधि में स्प्लैश स्क्रीन इंस्टॉल करें:

class SplashScreenActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        installSplashScreen()
        super.onCreate(savedInstanceState)

        setContent {
            WearApp()
        }
    }
}

अन्य संसाधन

स्प्लैश स्क्रीन के बारे में ज़्यादा जानें. साथ ही, यह भी जानें कि अपने ऐप्लिकेशन में इनका इस्तेमाल कैसे किया जा सकता है.