簡體   English   中英

以編程方式更改滾動條的顏色

[英]Change color of scrollbar programmatically

如何以編程方式更改滾動條的顏色?

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

我想創建TRANSPARENT滾動條。

您可以通過反射來實現:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM