Pastki navigatsiya panosining belgisining yuqori qismidagi rozetni ko'rsatish

Men ilovada pastki navigatsiya ko'rinishini joriy qildim va piktogrammalarning yuqori qismida nishonlarni ko'rsatish uchun har qanday joyni ko'rdim: bu Buni amalga oshirishning iloji bormi, deb hayron bo'ldim. Har qanday yordamni qadrlaymiz. Rahmat.

23
Albatta, bu mumkin. Siz pastki navigatsiya versiyasi uchun nashrda xml-da o'zingizni nishonchani yaratishingiz mumkin. Kvadrat maketini oching va menyu nishonchasini rozet ostiga qo'ying va sizning rozet ko'rinishini ko'rsatish/yashirish uchun mantiqni yarating.
qo'shib qo'ydi muallif velval, manba
@valval Buning qanday amalga oshirilishiga sizda kod misoli yoki qo'llanmasi bormi?
qo'shib qo'ydi muallif kalamar, manba

7 javoblar

Agar siz faqat BottomNavigationView aktsiyasini ishlatmoqchi bo'lsangiz va uchinchi tomon libasi bu erda qanday qilib qilgan bo'lsam:

BottomNavigationMenuView bottomNavigationMenuView =
            (BottomNavigationMenuView) navigationView.getChildAt(0);
    View v = bottomNavigationMenuView.getChildAt(3); 
    BottomNavigationItemView itemView = (BottomNavigationItemView) v;

    View badge = LayoutInflater.from(this)
            .inflate(R.layout.notification_badge, bottomNavigationMenuView, false);

    itemView.addView(badge);

Shundan so'ng bu erda tartib-fayl:



    

Keyin id kodi bilan TextView ni toping va matnni o'rnating. @ drawable/notification_badge - bu faqatgina aylana shaklidir

71
qo'shib qo'ydi
Juda sodda va u ishlaydi! Rahmat!
qo'shib qo'ydi muallif Andrew Odendaal, manba
Iltimos, javobni tahrirlab, chizilgan kodni qo'shib, tahmin ishlarini olib tashlashingiz mumkin. Men Androidda yangi va bu yordam beradi. :)
qo'shib qo'ydi muallif Adi, manba
hisobni o'zgartirish uchun quyidagi ikki qatorni bajaring: TextView notificationCount = badge.findViewById (R.id.notifications_badge); satrda sahifani qo'shishdan oldin notificationCount.setText (count); : elementView.addView (rozet);
qo'shib qo'ydi muallif Hesham Yassin, manba
Bu rozetni olib tashlash uchun faqat ushbu usuldan foydalaning. Public void removeBadge (BottomNavigationView navigationView, int index) {BottomNavigationMenuView bottomNavigationMenuView = (BottomNavigationMenuView) navigationView.getChildAt (0); Ko'rish v = bottomNavigationMenuView.getChildAt (index); BottomNavigationItemView elementView = (BottomNavigationItemView) v; itemView.removeViewAt (itemView.getChildCount() - 1); }
qo'shib qo'ydi muallif Nilesh Rathore, manba
@Ankit, OK, men sizni oldim, butun elementni itemView.getChildCount() - 1 dan foydalanganligim sababli o'chirib tashlamoqdasiz, buning o'rniga faqat qattiq kodli manzilni ishlatishingiz mumkin, agar pastki navigatsiyangiz faqatgina 1 nishon pozitsiyasi yoki sizning pastki navigatsiyangizda ushbu sarlavha bilan ishorali belgisi mavjud bo'lsa, faqatgina foydalaning. Yuqoridagi kodni yuqoridagi kodni o'zgartiring, vaziyatga ko'ra 1 yoki 2 pozitsiyadan foydalaning. itemView.removeViewAt (2);
qo'shib qo'ydi muallif Nilesh Rathore, manba
@Ankit, sizga qanday qilib rozetni qo'shish va o'chirish kodini baham ko'rasiz.
qo'shib qo'ydi muallif Nilesh Rathore, manba
Tabriklar @Ankit (y), siz nihoyat muvaffaqiyatga erishdingiz.
qo'shib qo'ydi muallif Nilesh Rathore, manba
@Nilesh Rathore, Kodni o'chirish ishlamasa, yuqoridagi kod barcha element ko'rinishini (rozet va belgi ham) o'chirib tashlaydi, faqat rozetni olib tashlash kerak, iltimos, faqat rozetni qanday qilib o'chirishi mumkinligini ayting
qo'shib qo'ydi muallif Ankit, manba
@Nilesh Rathore, endi rozilikni qisqartirishdan keyin hali ko'rsatilmayapti, u o'ldirilgandan keyin ilovada yana qaytib kelganimda o'chiriladi, nega darhol nishon belgisini olib tashlamaydi, darhol qo'shilsa, men ushbu belgi ko'rinishini yangilashga urindim, lekin buni qila olmadim har qanday muvaffaqiyatga erishish kerakmi?
qo'shib qo'ydi muallif Ankit, manba
@Nilesh Rathore, BottomNavigation android mahalliy kutubxonasini ( github.com/ittianyu/BottomNavigationViewEx ) o'zgartirdim. UI xabarnomasi nishoni yangilash uchun mening muammomni hal qildi.
qo'shib qo'ydi muallif Ankit, manba
BottomNavigationItemView FrameLayout xususiyatini kengaytirgandan buyon FrameLayout TextView
qo'shib qo'ydi muallif Victor Rendina, manba
u jozibasi kabi ishlaydi, lekin uni olib tashlashga harakat qilaman, buni qanday qilib qila olaman?
qo'shib qo'ydi muallif ismail alaoui, manba
@HeshamYassin sharhini qo'shish uchun, aslida rozet ko'rinishini o'chirishga hojat yo'q, buning o'rniga uning ko'rinishini sozlashingiz mumkin: notificationCount.setVisibility (View.GONE)
qo'shib qo'ydi muallif Igor Ilin, manba

When using support library Bottom Navigation bar, its quite complex to show a badge/notification on menu items. However there are easy solutions to get it done. Such as https://github.com/aurelhubert/ahbottomnavigation

Ushbu kutubxona Bottom Navigatsiya panjarasining yanada rivojlangan versiyasidir. Menyu elementidagi rozetni faqat shu kod snippetidan foydalanib o'rnatishingiz mumkin.

bottomNavigation.setNotification(notification, bottomNavigation.getItemsCount() - 1);

Va siz quyidagi natijaga erishasiz

enter image description here

16
qo'shib qo'ydi
Rahmat. Bugungi kunda uni amalga oshirishga harakat qilaman.
qo'shib qo'ydi muallif heisenberg91, manba

@Zxbin javob sifatida. BadgeView -ni tekshirib, quyidagi kodni sinab ko'rishingiz mumkin

BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(this);
navigation.setSelectedItemId(R.id.navigation_store);
BottomNavigationMenuView bottomNavigationMenuView =
        (BottomNavigationMenuView) navigation.getChildAt(0);
View v = bottomNavigationMenuView.getChildAt(4);//number of menu from left
new QBadgeView(this).bindTarget(v).setBadgeNumber(5);

source from my gist

3
qo'shib qo'ydi

Siz BadgeView dan foydalanishingiz mumkin;

Yoki githubda qidiruv.

2
qo'shib qo'ydi

base on @Tinashe's answer, i'd like badge show as bellow without number: enter image description here

kod:

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
       //position = 2
        addBadge(POSITION_HISTORY)
    }

    /**
     * add badge(notification dot) to bottom bar
     * @param position to get badge container
     */
    @SuppressLint("PrivateResource")
    private fun addBadge(position: Int) {
       //get badge container (parent)
        val bottomMenu = navigation.getChildAt(0) as? BottomNavigationMenuView
        val v = bottomMenu?.getChildAt(position) as? BottomNavigationItemView

       //inflate badge from layout
        badge = LayoutInflater.from(this)
                .inflate(R.layout.badge_layout, bottomMenu, false)

       //create badge layout parameter
        val badgeLayout: FrameLayout.LayoutParams = FrameLayout.LayoutParams(badge?.layoutParams).apply {
            gravity = Gravity.CENTER_HORIZONTAL
            topMargin = resources.getDimension(R.dimen.design_bottom_navigation_margin).toInt()

           //8dp
            leftMargin = resources.getDimension(R.dimen.bagde_left_margin).toInt()
        }

       //add view to bottom bar with layout parameter
        v?.addView(badge, badgeLayout)
    }

badge_layout.xml (badge_size = 12dp)


va chizilgan fon new_notification.xml

<?xml version="1.0" encoding="utf-8"?>

    
    

2
qo'shib qo'ydi

Siz shunday yo'lni sinashingiz mumkin:

Countdown ( BottomNavigationView FrameLayout ):

    
        
    

Va bunga shunday uslublar:




Va bottom_menu_selections_number_bg :


    
    

1
qo'shib qo'ydi

BottomNavigationView qo'llab-quvvatlash kutubxonasini ishlatish qiyin. Oddiy yechim tashqi qismlardan foydalanadi. Foydalanish oson: https://github.com/roughike/BottomBar Hujjatlarni tekshirish oson:

BottomBarTab nearby = bottomBar.getTabWithId(R.id.tab_nearby);
nearby.setBadgeCount(5);

// Remove the badge when you're done with it.
nearby.removeBadge/();
0
qo'shib qo'ydi