c# - Android(Xamarin):BottomNavigationView 没有出现在正确的位置
问题描述
我正在尝试使用命名空间中的BottomNavigationView
类Android.Support.Design.Widget
(Xamarin.Android.Support.Design 库,版本 28.0.0.3)为我的 Android 应用程序(API 30)实现底部导航栏。我正在关注这里的解释:https ://devblogs.microsoft.com/xamarin/exploring-androids-bottom-navigation-view/
这是布局文件的样子:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schema.android.com/apk/res/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/navigator"/>
<android.support.design.widget.BottomNavigationView android:id="@+id/navigator"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_gravity="bottom"
android:background="@android:color/white"
app:elevation="16dp"
app:menu="@menu/navigator"/>
</RelativeLayout>
这是菜单文件:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/home"
android:icon="@drawable/home"
android:title="Home"
android:enabled="true"
app:showAsAction="ifRoom"/>
<item android:id="@+id/library"
android:icon="@drawable/library"
android:title="Library"
android:enabled="true"
app:showAsAction="ifRoom"/>
<item android:id="@+id/search"
android:icon="@drawable/search"
android:title="Search"
android:enabled="true"
app:showAsAction="ifRoom"/>
</menu>
问题是,虽然它是可见的,但它出现在屏幕顶部而不是底部,这与底部导航栏应该做的完全相反。此外,它不显示图标。它只是在页面顶部显示为一个空白的白色条。
我做错了什么,我该如何解决?
解决方案
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:menu="@menu/navigation"
android:layout_gravity="bottom"
android:visibility="visible" />
推荐阅读
- ubuntu - DNS hoster 工作异常或不工作,如何检查?
- c++ - 类模板在其构造函数中的模板变量推导失败
- asp.net-mvc - HTML 助手
不包含“剑道”的定义 - 服务器错误 - ios - 使用 AFNetworking 上传图像
- javascript - 在 componentDidMount 上触发转换
- javascript - 如何使用 Ajax 将 WebGrid 发布到控制器
- django - Docker/Kubernetes + Gunicorn/Celery - 多个工人与副本?
- python - Py4JJava错误 | java.lang.IllegalArgumentException | 来自 Jupyter 的 Spark 错误 | 计数()不工作
- tensorflow - 无法在张量流中创建 MultiRNN 单元
- actionscript-3 - AS3 - 在 StageVideo 上检测触摸/点击