[英]BottomNavigationView - why is there not enough space for the badge Drawable?
我使用材料库中的BottomNavigationView
: const val material = "com.google.android.material:material:1.4.0-rc01"
并使用以下绑定在其上设置/更新徽章:
@BindingAdapter("cartCount")
fun BottomNavigationView.updateCartCount(count: Int) {
getOrCreateBadge(R.id.action_cart).apply {
isVisible = count > 0
if (isVisible) number = count
}
}
这是 XML 中的视图(在ConstraintLayout
)
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
cartCount="@{viewModel.cartCount}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/white"
app:elevation="8dp"
app:itemIconTint="@color/bottom_nav_item_color"
app:itemTextColor="@color/bottom_nav_item_color"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/menu_bottom_nav" />
我的问题是徽章似乎没有足够的空间:
当项目被选中时,哪个更明显:
我试图解决这个问题,但无济于事:
BottomNavigationView
的高度,在这里我将其设置为荒谬的 100dp:bottom_navigation_notification_padding
和这个答案中的其他一些bottom_navigation_notification_padding
我找不到与我的问题相关的任何“已知问题”。 我错过了什么?
在com.google.android.material:材料V1.3.0和上述可以使用setVerticalOffset
或setHorizontalOffset
的BadgeDrawable
与特定量水平或垂直移动的徽章在像素。
设置将此徽章垂直移向其锚点中心的量(以像素为单位)。
设置将此徽章向其锚点中心水平移动的量(以像素为单位)。
例子:
val menuItemId: Int = bottomNavigation.getMenu().getItem(1).getItemId()
val badge: BadgeDrawable = bottomNavigation.getOrCreateBadge(menuItemId)
badge.setVisible(true)
badge.setNumber(4)
badge.setVerticalOffset(10) //value in pix
badge.setHorizontalOffset(-10) //value in pix
带和不带偏移的结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.