繁体   English   中英

Shell 弹出式圆角

[英]Shell flyout with round corners

尝试通过设置圆角半径来自定义 Shell 弹出按钮,以便获得带有圆角的弹出按钮。 由于没有与 Shell 弹出角半径相关的属性,有没有办法使用自定义渲染器来实现?

不幸的是,当使用基于 AppShell 层次结构的自动生成的弹出内容时,我看不到在共享代码中执行此操作的方法(如果您要覆盖它,请跳到编辑部分),这是使用自定义完成它的解决方案Android 的渲染器:

  1. 在您的 Android 项目的Resources\drawable中,添加:

flyoutbackground.xml

<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/transparent" />
    <corners android:bottomRightRadius="30dp" android:topRightRadius="30dp" />
</shape>
  1. 在您的 Android 项目中,为您的 AppShell 实现一个ShellRenderer
[assembly: ExportRenderer(typeof(App1.AppShell), typeof(AppShellRenderer))]
namespace App1.Droid.Renderers
{
    public class AppShellRenderer : ShellRenderer
    {
        public AppShellRenderer(Context context) : base(context)
        {
        }

        protected override IShellFlyoutContentRenderer CreateShellFlyoutContentRenderer()
        {
            var flyoutContentRenderer = base.CreateShellFlyoutContentRenderer();
            var flyoutbackground = AppCompatResources.GetDrawable(Platform.CurrentActivity, Resource.Drawable.flyoutbackground);

            if (Android.OS.Build.VERSION.SdkInt > Android.OS.BuildVersionCodes.O)
            {
                flyoutbackground.SetColorFilter(new BlendModeColorFilter(
                    Shell.Current.FlyoutBackgroundColor.ToAndroid(), BlendMode.Color));
                flyoutContentRenderer.AndroidView.SetBackground(flyoutbackground);
            }
            else
            {
                flyoutbackground.SetColorFilter(Shell.Current.FlyoutBackgroundColor.ToAndroid(), PorterDuff.Mode.Src);
                flyoutContentRenderer.AndroidView.SetBackgroundDrawable(flyoutbackground);
            }
            return flyoutContentRenderer;
        }
}

渲染结果

在此处输入图像描述

局限性

  • 拐角半径是硬编码的。
  • 似乎不适用于 Android API <= 26,请随时修复/改进此答案的代码。

笔记

可以对Z1BDF6059919192CBDF8508204C4EBZ实施类似的类比,这是一个答案,可以帮助Z1B4419ABC4358B41D0CA507777A63908Z

相关问题: Shell TabBar 圆角,后面有视图

编辑

如果您使用Shell.FlyoutContentFlyoutContentTemplate覆盖弹出内容,而不是基于 AppShell 层次结构的自动生成内容,请检查@FabriBertani 注释,因为您不需要自定义渲染器来实现这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM