Wear OS पर व्यू पर आधारित यूज़र इंटरफ़ेस (यूआई) बनाना

Compose को आज़माएं
Wear OS पर Jetpack Compose, Wear OS के लिए सुझाया गया यूज़र इंटरफ़ेस टूलकिट है.

Android Jetpack में Wear OS की यूज़र इंटरफ़ेस लाइब्रेरी शामिल होती है. Wear OS यूज़र इंटरफ़ेस (यूआई) लाइब्रेरी में ये क्लास शामिल हैं:

  • CurvedTextView: यह एक ऐसा कॉम्पोनेंट है जिसकी मदद से, व्यू में मौजूद सबसे बड़े सर्कल के घुमाव के हिसाब से टेक्स्ट आसानी से लिखा जा सकता है.
  • DismissibleFrameLayout: यह एक ऐसा लेआउट है जिसमें उपयोगकर्ता, वापस जाएँ बटन दबाकर या स्क्रीन पर बाईं से दाईं ओर स्वाइप करके किसी भी व्यू को खारिज कर सकता है. Wear OS के उपयोगकर्ता, वापस जाने के लिए बाईं से दाईं ओर स्वाइप करने की सुविधा चाहते हैं.
  • WearableRecyclerView: यह एक ऐसा व्यू है जो WearableLinearLayoutManager का इस्तेमाल करके, चाइल्ड लेआउट को अपडेट करने के लिए बुनियादी ऑफ़सेटिंग लॉजिक उपलब्ध कराता है.
  • AmbientModeSupport: यह एक क्लास है, जिसका इस्तेमाल AmbientModeSupport.AmbientCallbackProvider इंटरफ़ेस के साथ किया जाता है, ताकि ऐंबियंट मोड की सुविधा दी जा सके.

पूरी सूची देखने के लिए, रिलीज़ नोट पढ़ें.

Wear OS यूज़र इंटरफ़ेस (यूआई) लाइब्रेरी की डिपेंडेंसी जोड़ना

ऐप्लिकेशन बनाने के लिए, Wear OS के लिए खास तौर पर बनाया गया प्रोजेक्ट बनाएं. इसके बाद, अपने ऐप्लिकेशन की build.gradle फ़ाइल में ये डिपेंडेंसी जोड़ें:

dependencies {
    ...
  // Standard Wear OS libraries
  implementation "androidx.wear:wear:1.2.0"
  // includes support for wearable specific inputs
  implementation "androidx.wear:wear-input:1.1.0"
}

Wear OS यूज़र इंटरफ़ेस (यूआई) लाइब्रेरी पैकेज से क्लास इंपोर्ट करना

Wear OS की यूज़र इंटरफ़ेस (यूआई) लाइब्रेरी से किसी क्लास का इस्तेमाल करने के लिए, उसे androidx.wear.widget पैकेज से इंपोर्ट करें.

लेआउट फ़ाइलों में सही एलिमेंट के नाम इस्तेमाल करना

लेआउट फ़ाइलों में, Wear OS UI लाइब्रेरी से जुड़े पूरे नाम इस्तेमाल करें.

उदाहरण के लिए, Wear OS यूज़र इंटरफ़ेस (यूआई) लाइब्रेरी से DismissibleFrameLayout क्लास का इस्तेमाल करने के लिए, लेआउट फ़ाइल में यह जानकारी दी जा सकती है:

<androidx.wear.widget.DismissibleFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/swipe_dismiss_root" >

    <TextView
        android:id="@+id/test_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="Swipe the screen to dismiss me." />
</androidx.wear.widget.DismissibleFrameLayout>