android自定义bottom,android – 如何将自定义菜单添加到Bottom App Bar?

本文介绍了在Android应用中如何使用MaterialBottomAppBar实现自定义菜单,重点解决菜单项仅显示3点而非图标的问题,分享了布局、Java代码及菜单设置的详细步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我在

android中使用新的Material Bottom应用程序栏.我已经成功实现了它,但我不知道如何将自定义菜单项添加到栏中.每当我添加菜单项时,即使我提供选项android:showAsAction =“always”,它们也只显示为3个点.

我想要特定的图标,如下面的屏幕截图

但相反,我得到这样的结果.

09dae225971caf943f01b9ab68db5fc4.png

这是布局代码.

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"/>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值