底部应用栏导航图标垂直居中不了。

5
我正在使用 android.support.design.bottomappbar.BottomAppBar ,但是当选项菜单添加时,导航图标会出现在左上角。

没有选项菜单时,它按预期工作(居中垂直)。

有选项菜单的情况下

enter image description here

没有选项菜单的情况下

enter image description here

有人能告诉我如何解决吗?

4个回答

7

在你的布局中,你可以将 BottomAppBar 主题 改为如下:

<android.support.design.bottomappbar.BottomAppBar
    ...
    android:theme="@style/Widget.MaterialComponents.BottomAppBar"
/>

5
尝试了不同的方法后,通过样式设置填充(padding)起作用了。
<style name="NavButtonPadding" parent="@android:style/Widget.ActionButton">
    <item name="android:paddingStart">10dp</item>
    <item name="android:paddingEnd">10dp</item>
    <item name="android:minWidth">10dp</item>
</style>

添加样式后


谢谢你! - Tgo1014
1
请确保声明新的 Material 样式。在我的 XML 中直接声明它对我很有帮助,同时添加以下内容:style="@style/Widget.MaterialComponents.BottomAppBar"。 - pancodemakes

2

当您使用Google Material组件时,最好将Theme.MaterialComponents主题作为应用程序的父主题:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">

替换为:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

style.xml 中。

0

我也遇到了同样的问题,但是通过添加以下内容找到了解决方案:

style="@style/Widget.MaterialComponents.BottomAppBar"

用于底部栏。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接