ScrollView中ScrollBar的颜色 [英] Color of ScrollBar in ScrollView

查看:60
本文介绍了ScrollView中ScrollBar的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

Xamarin.Forms ScrollView控件转换为每个平台上的本机滚动控件.您需要做的是创建一个自定义效果您可以访问这些基础控件.从那里可以自定义滚动条的外观.

在Android上,您需要使用 android.widget.ScrollView .您应该在资源文件夹中为滚动条定义一个自定义可绘制对象,并以编程方式将滚动条更改为效果内的滚动条.关于StackOverflow的答案很多,例如这里.

在iOS上,本机控件是UIKit中的 UIScrollView ,并且滚动条是预定义的图片,因此您可能需要在每次控件更新时替换图片. 此处.>

最后,您的XAML中将包含以下内容:

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

I use Xamarin.Forms, ScrollView, I can change ScrollView.Background, but background color of scroll bar don't change. How I can do it ? Can I make a universal shared style scrollbar for all platforms? If you can not, can I make so that I could use ScrollView in Shared project Xamarin.forms but at the same time that it is displayed at on different platforms with their own style? Maybe it can be done without their own styles and somehow easier? I need only custom scrollbar color in ScrollView Xamarin.Forms. I googled but found no examples of the using color of scrollbar Xamarin.forms. if it is not very easy to do, I would like to use an example code.

解决方案

The Xamarin.Forms ScrollView control translates to a native scroll control on each platform. What you need to do, is create a custom Effect that gives you access to those underlying controls. From there you can customize the appearance of the scrollbar.

On Android, you need to work with 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 StackOverflow that show you how to do it, for example here and here.

On iOS, the native control is 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 for a good starting point.

In the end, you'll have something like this in your XAML:

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

这篇关于ScrollView中ScrollBar的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆