Reputation: 181
I just want a custom scrollbar in my Listview with fastScrollEnabled but this doesn´t work! With fastScroll enabled, the custom scrollbar is not visible when scrolling normal and when scrolling fast, it's the default scrollbar. Without fastScrollEnabled is does work like it should be.
res\values\Styles.xlm:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:scrollbarThumbVertical">@drawable/scrollbar</item>
<item name="android:fastScrollThumbDrawable">@drawable/scrollbar</item>
<item name="android:fastScrollTrackDrawable">@drawable/scrollbar</item>
</style>
...
res\drawable\scrollbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="45"
android:endColor="#CC3401"
android:centerColor="#CC5c33"
android:startColor="#CC3401" />
<corners android:radius="8dp" />
<size android:width="4dp"/>
<padding
android:left="0.5dp"
android:right="0.5dp" />
</shape>
AndroidManifest.xml:
<application
android:theme="@style/AppTheme"
My Listview:
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff000020"
android:clickable="false"
android:fastScrollEnabled="true">
</ListView>
Can anyone please tell me what´s wrong here? Thanks!
Upvotes: 0
Views: 6752
Reputation: 181
Now, I know why I couldn´t do fastscroll. I use a Viewpager as parent of my Listview and the scrollbar position was at the very right on the screen. I needed to set the scrollbar position a little bit more to the left side to touch the scrollbar correctly for fast scrolling:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="20dp"> <!-- Margin -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="45"
android:centerColor="#CC6000"
android:endColor="#CC5000"
android:startColor="#CC5000"/>
<corners android:radius="8dp"/>
<size
android:width="6dp"
android:height="30dp"/>
</shape>
</item>
</layer-list>
Thanks again for your help, Luis!
Upvotes: 1
Reputation: 147
UPDATE
The short answer is: "thumb" and "track"are different things, do not put same style. When you area using "fastScrollbarEnabled", the "track" needs to have height and width.
old answer below
Apparently you need specify the "thumb" height when with the "fastScrollEnabled" enabled. You are putting the same drawable to "thumb" and "track", is your intention?
See my codes:
style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:fastScrollTrackDrawable">@drawable/fast_scrollbar_track</item>
<item name="android:fastScrollThumbDrawable">@drawable/fast_scrollbar</item>
<item name="android:scrollbarTrackVertical">@drawable/scrollbar_track</item>
<item name="android:scrollbarThumbVertical">@drawable/scrollbar</item>
</style>
</resources>
fast_scrollbar.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="45"
android:endColor="#ff00ff00"
android:centerColor="#ff00ff00"
android:startColor="#ff00ff00" />
<corners android:radius="8dp" />
<size android:width="4dp" android:height="50dp"/>
<padding
android:left="0.5dp"
android:right="0.5dp" />
</shape>
fast_scrollbar_track.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="45"
android:endColor="#ffff0000"
android:centerColor="#ffff0000"
android:startColor="#ffff0000" />
<corners android:radius="8dp" />
<size android:width="4dp" android:height="50dp"/>
<padding
android:left="0.5dp"
android:right="0.5dp" />
</shape>
scrollbar.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="45"
android:endColor="#ff00ff00"
android:centerColor="#ff00ff00"
android:startColor="#ff00ff00" />
<corners android:radius="8dp" />
<size android:width="4dp"/>
<padding
android:left="0.5dp"
android:right="0.5dp" />
</shape>
scrollbar_track.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="45"
android:endColor="#ffff0000"
android:centerColor="#ffff0000"
android:startColor="#ffff0000" />
<corners android:radius="8dp" />
<size android:width="4dp"/>
<padding
android:left="0.5dp"
android:right="0.5dp" />
</shape>
Prints of my device:
Upvotes: 1