问题
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.
回答1:
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>
...
来源:https://stackoverflow.com/questions/42469342/color-of-scrollbar-in-scrollview