LINUX.ORG.RU

material badge

 ,


0

1
package com.thesimplycoder.bottomnavbar

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
import android.graphics.Color
import androidx.core.app.NotificationCompat

class MainActivity : AppCompatActivity() {

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

        bottomNav.setOnNavigationItemSelectedListener {
            when (it.itemId) {
                R.id.menu_home -> {
                    setContent("Home")
                    true
                }
                R.id.menu_notification -> {
                    setContent("Notification")
                    true
                }
                R.id.menu_search -> {
                    setContent("Search")
                    true
                }
                R.id.menu_profile -> {
                    setContent("Profile")
                    true
                }
                else -> false
            }
        }
        // var badge = bottomNav.getOrCreateBadge(R.id.menu_home)
        // badge.isVisible = true
        // badge.number = 99
        // bottomNav.getOrCreateBadge(R.id.menu_home).apply {
        //     backgroundColor = Color.RED
        //     badgeTextColor = Color.WHITE
        //     maxCharacterCount = 3
        //     number = 0
        //     isVisible = true
        // }
        // val name = getString(R.id.menu_home)
        // val descriptionText = getString(R.string.channel_description)
        // val importance = NotificationManager.IMPORTANCE_LOW
        // val mChannel = NotificationChannel(id, name, importance).apply {
        //     description = descriptionText
        //     setShowBadge(false)
        // }
        // val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        // notificationManager.createNotificationChannel(mChannel)

        val messageCount = 12
        var notification = NotificationCompat.Builder(this@MainActivity, R.id.menu_home.toString())
        .setContentTitle("New Messages")
        .setContentText("You've received 3 new messages.")
        // .setSmallIcon(R.drawable.ic_notify_status)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setNumber(messageCount)
        .build()
    


    }

    private fun setContent(content: String) {
        setTitle(content)
        tvLabel.text = content
    }
}

Ничего не отображается

при(с офиц доки)

var badge = bottomNav.getOrCreateBadge(R.id.menu_home)
badge.isVisible = true
badge.number = 99

аплека падает. Что я делаю не так?

★★★★

Ответ на: комментарий от bryak

The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant)

Какой-то неверный атрибут передаешь в свой BadgeDrawable. В styles.xml тема твоей активити должна наследоваться от темы MaterialComponents. Ещё может потребуется подключить «com.google.android.material:material:1.1.0»

arty_bishop
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.