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

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

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

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

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

Groovy

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

Kotlin

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

पक्का करें कि आपने 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.IconBackground">
    ...
    <!-- Set a white background behind the splash screen icon. -->
    <item name="windowSplashScreenIconBackgroundColor">@android:color/white</item>
</style>

अन्य एट्रिब्यूट की वैल्यू देना ज़रूरी नहीं है.

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

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

<?xml version="1.0" encoding="utf-8"?>
<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 में तय किया जाता है. यह इस बात पर निर्भर करता है कि आइकॉन गोल है या नहीं:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Round app icon can take all of default space -->
    <dimen name="splash_screen_icon_size">48dp</dimen>
</resources>

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

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Non-round icon with background must use reduced size to fit circle -->
    <dimen name="splash_screen_icon_size">36dp</dimen>
</resources>

थीम की जानकारी देना

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

<manifest>
    <application android:theme="@style/Theme.App.Starting">
       <!-- or -->
       <activity android:theme="@style/Theme.App.Starting">
          <!-- ... -->
</manifest>

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

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

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        // Handle the splash screen transition.
        installSplashScreen()

        super.onCreate(savedInstanceState)
        setContent {
            WearApp("Wear OS app")
        }
    }
}

अन्य संसाधन

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