4

I'm working on a fast scrollbar. I want to use the Android 5.1 style fast scrollbar on older devices (I'm testing on Android 5.0.2, API 21). Here's a picture of what I've got so far. (I can't post photos yet because of the reputation system (I'm new here), so it's a link to my Google Photos.)

https://goo.gl/photos/YihnpUN3SfjLjjB8A

Here's my problem: I want the scrollbar track (the gray part) to take the whole height of the screen (more exactly the whole height of the content). Now it begins few pixels below the action bar, and ends few pixels above the navigation bar - and I'd like it to begin right under the action bar and to end right above the navigation bar.

Here's my code implementation:

drawable fastscroll_thumb.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <layer-list>
            <item android:left="8dp">
                <shape
                    android:tint="?attr/colorControlActivated"
                    android:shape="rectangle">
                    <solid android:color="@color/colorPrimaryDark" />
                    <size
                        android:width="8dp"
                        android:height="48dp" />
                </shape>
            </item>
        </layer-list>
    </item>
    <item>
        <layer-list>
            <item android:left="8dp">
                <shape
                    android:tint="?attr/colorControlNormal"
                    android:shape="rectangle">
                    <solid android:color="@color/colorPrimary" />
                    <size
                        android:width="8dp"
                        android:height="48dp" />
                </shape>
            </item>
        </layer-list>
    </item>
</selector>

drawable fastscroll_track.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list>
            <item android:left="8dp">
                <shape
                    android:tint="?attr/colorControlNormal"
                    android:shape="rectangle">
                    <solid android:color="@color/fastScrollTrack" />
                    <size android:width="8dp" />
                </shape>
            </item>
        </layer-list>
    </item>
</selector>

I'm using a fragment for the list:

fragment layout file

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ListView
        android:id="@+id/all_songs_fragment"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="@android:color/transparent"
        android:drawSelectorOnTop="true"
        android:focusable="true"
        android:clickable="true"
        android:fastScrollEnabled="true" />
</LinearLayout>

styles.xml

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb</item>
        <item name="android:fastScrollTrackDrawable">@drawable/fastscroll_track</item>
    </style>
</resources>

I think that what's going on is that I'm just changing "theme" of the fast scrollbar. Since I'm using API 21, the stock scrollbar looks differently (it's just a thin line with a smaller thumb - https://goo.gl/photos/T15JVGgpisqqYSd26). I've managed to make the thumb 48dp high and 8dp wide, as it's supposed to be. However, I'm not able to change the height of the track. I would like to set it to something like "fill_parent", but I can't - the only allowed units are px, dp, sp, in and mm. Is there any simple workaround, or do I have to dig deeper into the fastscroll implementation?

One more question: could anybody tell me the proper color of the fastscroll track? I'm currently using #21000000.

Thanks.

Vratislav Jindra
  • 551
  • 5
  • 16

0 Answers0