ScrollView 中 ScrollBar 的颜色

Color of ScrollBar in ScrollView

我用Xamarin.FormsScrollView,我可以改ScrollView.Background,但是滚动条的背景颜色没有变。我该怎么做? 我可以为所有平台制作一个通用的共享样式滚动条吗? 如果你不能,我可以做这样我可以在共享项目 Xamarin.forms 中使用 ScrollView 但同时它显示在 在不同的平台上有自己的风格? 也许它可以在没有自己的风格的情况下完成并且更容易?我只需要 ScrollView Xamarin.Forms 中的自定义滚动条颜色。 我用谷歌搜索,但没有找到使用滚动条 Xamarin.forms 颜色的示例。 如果不是很容易做到,我想使用示例代码。

Xamarin.FormsScrollView 控件转换为每个平台上的本机滚动控件。您需要做的是创建一个自定义 Effect,使您可以访问这些底层控件。从那里您可以自定义滚动条的外观。

在 Android,您需要使用 android.widget.ScrollView. You should define a custom drawable for the scrollbar in your resources folder and programmatically change the scrollbar to that inside your effect. There are quite a few answers on Whosebug that show you how to do it, for example here and here

在 iOS 上,原生控件 UIScrollView from UIKit and the scrollbars are predefined images so you'll probably need to replace the image each time the control updates. Take a look here 是一个很好的起点。

最后,您的 XAML 中会出现这样的内容:

<ScrollView>
    <ScrollView.Effects>
        <local:ScrollBarColorEffect ScrollBarColor="Green" />
    </ScrollView.Effects>
 ...