有没有办法自定义NavigationView滚动条和拇指颜色 现在它被报告为bug并且无法自定义。错误的链接是here
有没有人在导航视图的滚动视图中进行自定义分享。
答案 0 :(得分:0)
经过几个小时的RnD后,我发现这个解决方案有助于动态改变拇指颜色而不是xml
private void navigationViewScrollThumbColor(NavigationView navigationView) {
if (navigationView != null) {
NavigationMenuView navigationMenuView = (NavigationMenuView) navigationView.getChildAt(0);
if (navigationMenuView != null) {
try {
Field mScrollCacheField = View.class.getDeclaredField("mScrollCache");
mScrollCacheField.setAccessible(true);
Object mScrollCache = mScrollCacheField.get(navigationMenuView);
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.color_of_your_Choice));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}