我在
android中使用新的Material Bottom应用程序栏.我已经成功实现了它,但我不知道如何将自定义菜单项添加到栏中.每当我添加菜单项时,即使我提供选项android:showAsAction =“always”,它们也只显示为3个点.
我想要特定的图标,如下面的屏幕截图
但相反,我得到这样的结果.
这是布局代码.
android:id="@+id/bottom_app_bar"
style="@style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
app:backgroundTint="@color/colorPrimaryDark"
app:fabCradleMargin="5dp"
app:fabAlignmentMode="center"/>
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/bottom_app_bar" />
这是java代码.
BottomAppBar bottomAppBar = (BottomAppBar) findViewById(R.id.bottom_app_bar);
setSupportActionBar(bottomAppBar);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.navigation, menu);
return true;
}
菜单代码.
android:id="@+id/navigation_explore"
android:icon="@drawable/explore"
android:title="Explore"
android:showAsAction="always"/>
android:id="@+id/navigation_profile"
android:icon="@drawable/profile"
android:title="Profile"
android:showAsAction="always"/>