以编程方式更改滚动条的颜色

时间:2015-07-02 13:28:28

标签: c# android xamarin scrollbar scrollview

如何以编程方式更改滚动条的颜色?

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

我想创建TRANSPARENT滚动条。

1 个答案:

答案 0 :(得分:0)

你可以通过反思来实现这个目标:

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();
}