cj1098
cj1098

Reputation: 1610

scrollBar in a listView...customizing it.

Is there a way to customize the standard scrollbar that ListView provides in android..? I haven't got a definitive answer on this yet :/

Upvotes: 8

Views: 7966

Answers (2)

JamisonMan111
JamisonMan111

Reputation: 200

You can also specify it in the ListView or ScrollView that is in your layout. I have a provided a screenshot example from my code:

enter image description here

<ListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/divider_bar"
    android:layout_marginTop="5dp"

    android:scrollbarAlwaysDrawVerticalTrack="true"
    android:scrollbarStyle="outsideOverlay"
    android:scrollbars="vertical"
    android:fadeScrollbars="true"
    android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"
    android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"
    android:scrollbarFadeDuration="500"
    android:scrollbarDefaultDelayBeforeFade="1000">
</ListView>

Upvotes: 2

Konstantin Burov
Konstantin Burov

Reputation: 69238

Create a theme in res/styles.xml:

<style name="CustomTheme" parent="android:Theme">
    <item name="android:scrollbarTrackVertical">@drawable/scroll_track</item>
    <item name="android:scrollbarThumbVertical">@drawable/scroll_thumb</item>
</style>

@drawable/scroll_track and @drawable/scroll_thumb must refer either to nine patch images or to a shape drawables. Scroll track image is a background for the scroll bar. Scroll thumb is responsible for the scroll handle. Then just apply the theme either to whole application or to an activity within AndroidManifest.xml:

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/CustomTheme">

Upvotes: 15

Related Questions