簡體   English   中英

如何將徽章添加到Android TabLayout

[英]How to add Badge to Android tablayout

我想將徽章添加到我的TabLayout 當每個添加新元素(項目ListView )在數據庫中時,我想顯示一個徽章(+1),以便通知用戶每個新元素。

喜歡這張圖片:

任何幫助,將不勝感激

  1. 為每個TAB設計一個custom view
  2. 使用TAB.setCustomView(custom_View)為每個TAB設置custom view

嘗試這個:

    // Tab
    Tab tab = YourTabLayout.getTabAt(position);

    // Get Custom view using LayoutInflater
    // ...........

    // Set custom view
    tab.setCustomView(custom_View);

您將需要向每個選項卡添加自定義View 因此,一旦完成ViewPagerAdapter設置。

遍歷選項卡並添加自定義視圖。

就像是:

for (int i = 0; i < tabLayout.getTabCount(); i++) {
    TabLayout.Tab tab = tabLayout.getTabAt(i);
    tab.setCustomView(createCustomViewForTab(i);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM