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

अगर आपके ऐप्लिकेशन में, पसंद के मुताबिक स्प्लैश स्क्रीन लागू की गई है या लॉन्चर थीम का इस्तेमाल किया गया है, तो अपने ऐप्लिकेशन को 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")
}

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

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

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()
        }
    }
}

अन्य संसाधन

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