Shell TabBar 圆角覆盖后面的默认背景颜色(视图)

人气:499 发布:2022-10-16 标签: c# xamarin.forms custom-renderer xamarin.forms.shell

问题描述

我在 Shell TabBar 上应用圆角,例如

解决方案

您可以将 Parent 的 BackgroundColor 设置为当前 ContentPage BackgroundColor 或者它 Content(可能是一个布局)BackgroundColor.

 public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement 外观){var currentContentPage = (Shell.Current.CurrentPage as ContentPage);if (currentContentPage == null){返回;}if (currentContentPage.Content != null && currentContentPage.Content.BackgroundColor != Color.Transparent){(bottomView.Parent as LinearLayout)?.SetBackgroundColor(currentContentPage.Content.BackgroundColor.ToAndroid());}别的{(bottomView.Parent as LinearLayout)?.SetBackgroundColor(currentContentPage.BackgroundColor.ToAndroid());}bottomView.SetBackgroundResource(Resource.Drawable.bottombackground);}

注意

由于是后续问题,所以我只放了针对这个问题的相关代码,完整代码可以在https://stackoverflow.com/a/65784730>/stackoverflow.com/a/65784730

I'm applying rounded corner on a Shell TabBar like in Xamarin Forms Shell TabBar Rounded Corner.

My question: is it possible to put the view (background color) behind instead of above (default black color)?

解决方案

You can set the BackgroundColor of the Parent to either the current ContentPage BackgroundColor or to it Content (probably a Layout) BackgroundColor.

    public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
        {
            var currentContentPage = (Shell.Current.CurrentPage as ContentPage);
            if (currentContentPage == null)
            {
                return;
            }

            if (currentContentPage.Content != null && currentContentPage.Content.BackgroundColor != Color.Transparent)
            {
                (bottomView.Parent as LinearLayout)?.SetBackgroundColor(currentContentPage.Content.BackgroundColor.ToAndroid());
            }
            else
            {
                (bottomView.Parent as LinearLayout)?.SetBackgroundColor(currentContentPage.BackgroundColor.ToAndroid());
            }

            bottomView.SetBackgroundResource(Resource.Drawable.bottombackground);
        }

Note

Since it is a follow-up question I just put the relevant code specific for this question, the full code could be found in https://stackoverflow.com/a/65784730

710