如何解决Xamarin Shell android 使用 xml 标记自定义
我已经定义了自定义的底部视图来在 android 项目中制作自定义的 tabbar shell。
为此,我创建了一个新的渲染和一个新的 xml 文件来定义图形。
但是有一个问题,我有 margin
但底部视图下的背景是黑色的,我不知道如何编辑这种颜色。
这是我的代码:
public class MyShellBottomNavViewAppearanceTracker : IShellBottomNavViewAppearanceTracker
{
public void SetAppearance(BottomNavigationView bottomView,IShellAppearanceElement appearance)
{
bottomView.SetBackgroundResource(Resource.Drawable.bottomBack);
if (bottomView.LayoutParameters is LinearLayout.LayoutParams layoutParams)
{
layoutParams.SetMargins(30,30,0);
bottomView.LayoutParameters = layoutParams;
}
}
}
这是我的shell xml:
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#fff555" />
<corners android:topLefTradius="15dp"
android:topRighTradius="15dp"
android:bottomLefTradius="15dp"
android:bottomrighTradius="15dp"
/>
<padding android:top="5dp" android:bottom="5dp"/>
</shape>
结果显示为灰色背景,外壳为黄色,背景为黑色,但对于最后一个我不知道如何编辑(将灰色作为视图的其余部分)。
Screen about background tab bar is black and not gray as rest of the view
如何指定标签栏背景(超出边距)?
解决方法
您可以尝试获取bottomView的Parent,然后将其背景颜色设置为灰色。
public void SetAppearance(BottomNavigationView bottomView,IShellAppearanceElement appearance)
{
bottomView.SetBackgroundResource(Resource.Drawable.bottombackground);
Android.Views.View view = (Android.Views.View)bottomView.Parent;
view.SetBackgroundColor(Android.Graphics.Color.Gray);
if (bottomView.LayoutParameters is LinearLayout.LayoutParams layoutParams)
{
layoutParams.SetMargins(30,30,0);
bottomView.LayoutParameters = layoutParams;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。