【问题标题】:Change color of scrollbar programmatically以编程方式更改滚动条的颜色
【发布时间】:2015-07-02 13:28:28
【问题描述】:

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

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

我想创建透明滚动条。

【问题讨论】:

标签: c# android xamarin scrollbar scrollview


【解决方案1】:

您可以通过反射来实现:

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

【讨论】:

  • 我没有类Field、View.class、Object
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-06
  • 2021-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多