[英]Android Wear notifications: full screen
您可以將活動嵌入到磨損通知中,如下所示:
Notification myFullScreenNotification = new Notification.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentText(notificationText)
.extend(new Notification.WearableExtender()
.setCustomSizePreset(Notification.WearableExtender.SIZE_FULL_SCREEN)
.setDisplayIntent(PendingIntent.getActivity(context, 0, new Intent(context, MyActivity.class), 0)))
.build();
確保在AndroidManifest.xml中提供正確的權限:
<activity
android:name=".MyActivity"
android:exported="true"
android:allowEmbedded="true"
android:taskAffinity="" />
通知顯示正常,直到用戶向上滑動,然后它將變為全屏並在頁面上運行活動。
如果要將“活動”用作“通知”的輔助頁面,請將上面的“通知”作為另一個通知的頁面插入,如下所示:
Notification myWearNotification = new Notification.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentText(notificationText)
.extend(new Notification.WearableExtender()
.addPage(myFullScreenNotification)
.build();
需要Android Wear應用才能完全自定義通知的布局。
我嘗試編寫一個自定義庫,它從手機中發布布局xml以進行磨損和膨脹,但由於與LayoutInflator相關的限制,這是不可能的 。
以下是相關的參考位: 出於性能原因,視圖通脹在很大程度上依賴於在構建時完成的XML文件的預處理。 因此,目前無法在運行時對普通XML文件使用帶有XmlPullParser的LayoutInflater; 它只適用於從編譯資源(R.something文件)返回的XmlPullParser。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.