欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

一、氣泡配置信息 

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

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

氣泡是通過(guò)Notification API創(chuàng)建的。我們?nèi)绻屚ㄖ@示氣泡效果,需要添加一些配置信息。因?yàn)闅馀莸恼归_(kāi)視圖是根據(jù)選擇的Activity來(lái)創(chuàng)建的,此Activity需要經(jīng)過(guò)配置才能顯示為氣泡。此Activity必須是可以調(diào)整大小、嵌入式的,并始終可以在文檔模式界面下啟動(dòng)。如下代碼是氣泡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ā)送氣泡的實(shí)例代碼如下:

// 創(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)建展開(kāi)的氣泡

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

Java實(shí)例代碼如下:

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

kotlin實(shí)例代碼如下:

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

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

相關(guān)文章

最新評(píng)論