Android(Xamarin)中BottomNavigationView位置错误且无图标如何解决
问题原因及修复方案
导航栏位置错位问题
原因
根布局使用RelativeLayout时,android:layout_gravity属性不属于RelativeLayout的子控件有效属性,仅对FrameLayout、LinearLayout等父布局生效。你未给BottomNavigationView添加对齐父布局底部的专属属性,控件默认从布局顶部开始排列,因此出现位置错位。
修复方法
给BottomNavigationView控件添加android:layout_alignParentBottom="true"属性即可。
导航栏不显示图标和菜单问题
原因
根布局中app命名空间配置错误,你当前写的地址是http://schema.android.com/apk/res/res-auto,正确的官方声明地址应为http://schemas.android.com/apk/res-auto。命名空间错误导致app:menu等自定义属性无法被系统识别,菜单资源没有加载到导航控件中,因此只显示空白的白色背景条。
修复方法
修正根布局的app命名空间声明即可。
修正后完整布局代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/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_alignParentBottom="true" android:background="@android:color/white" app:elevation="16dp" app:menu="@menu/navigator"/> </RelativeLayout>
菜单文件无需额外修改,修正布局后两个问题即可同步解决。
内容的提问来源于stack exchange,提问作者Carnagion
相关产品推荐
相关产品推荐

