Android 带有自定义项的底部导航视图(actionLayout)
我想在新文件夹中添加一个自定义项 有很多教程介绍如何使用普通导航视图添加自定义视图,但我找不到关于底部视图的任何内容 这是我的看法Android 带有自定义项的底部导航视图(actionLayout),android,android-view,android-menu,Android,Android View,Android Menu,我想在新文件夹中添加一个自定义项 有很多教程介绍如何使用普通导航视图添加自定义视图,但我找不到关于底部视图的任何内容 这是我的看法 <android.support.design.widget.BottomNavigationView android:id="@+id/navigation_view" android:layout_width="match_parent" android:layout_height="wrap_cont
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/menu_main" />
这是菜单
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_one"
android:icon="@drawable/ic_tab_one"
android:title="one" />
<item
android:id="@+id/menu_two"
app:actionLayout="@layout/item_action_notification"
android:title="two" />
如您所见,我像往常一样放置了actionLayout标记,但它只是不显示
有什么想法吗?谢谢。希望下面的解决方案能有所帮助
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/cart_badge"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="top|center_horizontal"
android:layout_marginLeft="10dp"
android:background="@drawable/circle"
android:backgroundTint="@color/colorAccent"
android:gravity="center"
android:text="0"
android:textColor="@android:color/white"
android:textSize="12sp" />
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.MainActivity">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bot_nav"
android:layout_width="0dp"
android:layout_height="56dp"
android:background="@color/white"
android:elevation="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_menu" />
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_home"
android:icon="@drawable/home24"
android:title="Home" />
<item
android:id="@+id/menu_cart"
android:icon="@drawable/shoppingcart24"
android:title="Cart" />
<item
android:id="@+id/menu_acct"
android:icon="@drawable/user24"
android:title="Account" />
</menu>
谢谢你Manza,你找到这个问题的解决方案了吗?我也遇到了同样的情况。我尝试使用action布局和action view类,但什么也看不到。@aNoviceGuy不幸的是,我不同意:(你知道如何在它们之间添加分隔符吗?>@AnshulTyagi,用a包装会在菜单项之间出现分隔符。@Manza你找到解决方法了吗?很抱歉,我错误地否决了你的答案,这只会起作用fine@KaustubhBhagwat投票没问题,你说得对,谢谢:)工作完美,感谢@PramilaShankarThank you@SachinAble添加徽章,但在菜单项之间切换时面临问题。选择菜单项时,标签向上缩放,菜单图标移位,但徽章不会移位,导致徽章错位。有任何建议@PramilaShankar
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_home"
android:icon="@drawable/home24"
android:title="Home" />
<item
android:id="@+id/menu_cart"
android:icon="@drawable/shoppingcart24"
android:title="Cart" />
<item
android:id="@+id/menu_acct"
android:icon="@drawable/user24"
android:title="Account" />
</menu>
BottomNavigationView mbottomNavigationView =findViewById(R.id.bot_nav);
BottomNavigationMenuView mbottomNavigationMenuView =
(BottomNavigationMenuView) mbottomNavigationView.getChildAt(0);
View view = mbottomNavigationMenuView.getChildAt(1);
BottomNavigationItemView itemView = (BottomNavigationItemView) view;
View cart_badge = LayoutInflater.from(this)
.inflate(R.layout._custom_cart_item_layout,
mbottomNavigationMenuView, false);
itemView.addView(cart_badge);