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

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

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

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

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

Groovy

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

Kotlin

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

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

थीम जोड

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

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

बैकग्राउंड को काले रंग से भरने के लिए, windowSplashScreenBackground का इस्तेमाल करें रंग. postSplashScreenTheme की वैल्यू को उस थीम के हिसाब से सेट करें जिसे Activity ड्रॉ करने लायक या ऐनिमेशन के लिए 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")
        }
    }
}

अन्य संसाधन

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