亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android Q之氣泡彈窗的實現(xiàn)示例

 更新時間:2020年06月23日 10:57:54   作者:徐福記456  
這篇文章主要介紹了Android Q之氣泡彈窗的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

在Android Q中,用戶可以借助氣泡,輕松地在設(shè)備上任何位置進(jìn)行多任務(wù)處理。氣泡內(nèi)置于“通知”系統(tǒng)中,它會浮動在其他應(yīng)用的上層,并會跟隨用戶的移動而移動到屏幕的任何位置,用于取代SYSTEM_ALERT_WINDOW。氣泡可以展開顯示應(yīng)用功能和信息,并在不使用時折疊起來。當(dāng)設(shè)備處于已鎖定狀態(tài)或始終保持活動狀態(tài),氣泡會像通知那樣顯示。氣泡彈窗效果如下圖:

一、氣泡配置信息 

氣泡是一種可以選擇停用的功能,在應(yīng)用顯示第一個氣泡時,系統(tǒng)會彈出權(quán)限對話框,提供兩種選項:

  • 屏蔽來自您的應(yīng)用的所有氣泡 - 通知不會被屏蔽,但永遠(yuǎn)不會顯示為氣泡;
  • 允許來自您的應(yīng)用的所有氣泡 - 通過 BubbleMetaData 發(fā)送的所有通知都會顯示為氣泡;

氣泡是通過Notification API創(chuàng)建的。我們?nèi)绻屚ㄖ@示氣泡效果,需要添加一些配置信息。因為氣泡的展開視圖是根據(jù)選擇的Activity來創(chuàng)建的,此Activity需要經(jīng)過配置才能顯示為氣泡。此Activity必須是可以調(diào)整大小、嵌入式的,并始終可以在文檔模式界面下啟動。如下代碼是氣泡Activity的配置:

<activity
   android:name=".BubbleActivity"
   android:theme="@style/AppTheme.NoActionBar"
   android:label="@string/title_activity_bubble"
   android:allowEmbedded="true"
   android:documentLaunchMode="always"
   android:resizeableActivity="true"
  />

二、發(fā)送氣泡 

要發(fā)送氣泡,需要執(zhí)行如下步驟:

發(fā)送氣泡的實例代碼如下:

// 創(chuàng)建氣泡intent
  Intent target = new Intent(mContext, BubbleActivity.class);
  PendingIntent bubbleIntent =
    PendingIntent.getActivity(mContext, 0, target, 0 /* flags */);
 
  // 創(chuàng)建氣泡元數(shù)據(jù)
  Notification.BubbleMetadata bubbleData =
    new Notification.BubbleMetadata.Builder()
      .setDesiredHeight(600)
      // Note: although you can set the icon is not displayed in Q Beta 2
      .setIcon(Icon.createWithResource(context, R.drawable.icon))
      .setIntent(bubbleIntent)
      .build();
 
  // 創(chuàng)建通知
  Person chatBot = new Person.Builder()
      .setBot(true)
      .setName("BubbleBot")
      .setImportant(true)
      .build();
 
  Notification.Builder builder =
    new Notification.Builder(mContext, CHANNEL_ID)
      .setContentIntent(contentIntent)
      .setSmallIcon(smallIcon)
      .setBubbleMetadata(bubbleData);

三、創(chuàng)建展開的氣泡

我們可以將氣泡配置為自動展開顯示,可以使用以下方法來設(shè)置用于啟用這些行為的標(biāo)記:setAutoExpandBubble()setSuppressInitialNotification()

Java實例代碼如下:

Notification.BubbleMetadata bubbleData =
        new Notification.BubbleMetadata.Builder()
            .setDesiredHeight(600)
            .setIntent(bubbleIntent)
            .setAutoExpandBubble(true)
            .setSuppressInitialNotification(true)
            .build();

kotlin實例代碼如下:

val bubbleMetadata = Notification.BubbleMetadata.Builder()
    .setDesiredHeight(600)
    .setIntent(bubbleIntent)
    .setAutoExpandBubble(true)
    .setSuppressInitialNotification(true)
    .build()

到此這篇關(guān)于Android Q之氣泡彈窗的實現(xiàn)示例的文章就介紹到這了,更多相關(guān)AndroidQ 氣泡彈窗內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論