0

How can I change color of my scroll bar programmatically?

ScrollView scrollView1 = new ScrollView(context);
scrollView1.LayoutParameters = lparams;
scrollView1.LayoutParameters.Height = chartHeight;
scrollView1.LayoutParameters.Width = scrollWidth;

I want to create TRANSPARENT scroll bar.

Kirill
  • 1,412
  • 4
  • 21
  • 45
  • refer this http://stackoverflow.com/questions/21806852/change-the-color-of-scrollview-programmatically – sasikumar Jul 02 '15 at 13:30
  • I use Xamarin Android (C# code), not Java – Kirill Jul 02 '15 at 13:36
  • This guy wanted to change the speed of the scroll bar. http://forums.xamarin.com/discussion/comment/20938/#Comment_20938 Seems you will need to create a customer ScrollView Control – InitLipton Jul 02 '15 at 15:07

1 Answers1

0

You can achieve this via reflection:

try
{
    Field mScrollCacheField = View.class.getDeclaredField("mScrollCache");
    mScrollCacheField.setAccessible(true);
    Object mScrollCache = mScrollCacheField.get(listview);
    Field scrollBarField = mScrollCache.getClass().getDeclaredField("scrollBar");
    scrollBarField.setAccessible(true);
    Object scrollBar = scrollBarField.get(mScrollCache);
    Method method = scrollBar.getClass().getDeclaredMethod("setVerticalThumbDrawable", Drawable.class);
    method.setAccessible(true);
    method.invoke(scrollBar, getResources().getDrawable(R.drawable.scrollbar_style));
}
catch(Exception e)
{
    e.printStackTrace();
}
Anandu
  • 145
  • 1
  • 4