【问题标题】:Updating Color of custom ScrollBar UI更新自定义 ScrollBar UI 的颜色
【发布时间】:2017-02-18 08:59:38
【问题描述】:

如何使用自定义 BasicScrollBarUI 重新设置 ScrollBar 的颜色?

我知道我可以用它第一次设置颜色:

protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)

但是,这是由构造函数调用的,我不能再次手动调用它。

我需要滚动条的颜色来更改触发时间和动作。

我该怎么做?

【问题讨论】:

标签: java swing user-interface jscrollpane


【解决方案1】:

我不确定您需要什么,但如果这有帮助,请告诉我

ScrollView scr = (ScrollView)findViewById(R.id.scrollView1);
try
{
Field mScrollCacheField = View.class.getDeclaredField("mScrollCache");
mScrollCacheField.setAccessible(true);
Object mScrollCache = mScrollCacheField.get(scr); // scr is your Scroll View

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

// Set your drawable here.
method.invoke(scrollBar, getResources().getDrawable(R.drawable.scrollbar_blue));
} catch(Exception e) {
e.printStackTrace();
}

listview.mScrollCache.scrollBar.setVerticalThumbDrawable(getResources().getDrawable(R.drawable.scrollbar_style));

【讨论】:

    猜你喜欢
    • 2015-08-15
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 2016-01-30
    相关资源
    最近更新 更多