Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :/

like image 892
cj1098 Avatar asked Jul 30 '11 02:07

cj1098


2 Answers

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">
like image 160
Konstantin Burov Avatar answered Nov 19 '22 13:11

Konstantin Burov


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>
like image 2
JamisonMan111 Avatar answered Nov 19 '22 13:11

JamisonMan111