RecyclerView自定义ScroolBar样式后,ScrollBar不出现
最近做项目,需要对RecyclerView设置自定义scroolBar样式,可是滚动条死活不出现
代码如下activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<yiyou.yinhui.sh.cn.myapplication.fastscroll.views.FastScrollRecyclerView
android:id="@+id/recyclerView_search_keyword_result_list"
style="@style/ZoomItemRecyclerView_style"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:fastScrollTrackColor="#60606D"
app:fastScrollThumbInactiveColor="#008EE3"
/>
</RelativeLayout>
引用的style代码
<style name="RecyclerView_style">
<item name="android:layout_marginRight">10dp</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="android:scrollbarSize">2dp</item>
<item name="android:overScrollMode">never</item>
</style>
刚开始我以为是自定义样式的锅,好,用原生的总该没问题了吧。结果,还是不出现
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_search_keyword_result_list"
style="@style/ZoomItemRecyclerView_style"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
/>
</RelativeLayout>
看代码并没有问题是吧。于是我开始百度,查找RecyclerView的滚动条不出现的原因。然而并没有发现有跟我出现类似的问题的答案。没办法,网上找不到,那就一个一个排除吧,最后发现把ZoomItemRecyclerView_style中
<item name="android:overScrollMode">never</item>
去掉就能够正常显示了,那么如果要设置android:overScrollMode的属性怎么弄了。我们可以在代码里面动态的设置setOverScrollMode(View.OVER_SCROLL_NEVER);
注意
android 26以上,RecyclerView就支持了fastScroll,用原生的fastScroll设置的时候不受影响。
项目地址
recyclerView_scrollbar.