Android ListView fastScrollThumbDrawable not working
NickName:user1217891 Ask DateTime:2012-02-19T18:04:56

Android ListView fastScrollThumbDrawable not working

i am doing an app where i want the fastscroll tab on my listview to be a custom thumb tab. reading the docs online i thought this would do it:

<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:cacheColorHint="@color/myWhite"
android:scrollbars="vertical"
android:scrollbarThumbVertical="@drawable/scrollthumb"
android:scrollbarSize="12dip"
android:fastScrollThumbDrawable="@drawable/scrollbar_thumb"
android:fastScrollEnabled="true"
/>

The list view is fine, the custom scrollbar colours are working and the fastscrollbar tab displays, but it is using the default thumb image and not the png file scrollbar_thumb.

does the thumb image need to be in a certain format or size ? can it be changed to a custom graphic, if not can the colour of the thumb be changed at least ?

any help will be much appreciated

Copyright Notice:Content Author:「user1217891」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/9348291/android-listview-fastscrollthumbdrawable-not-working

Answers
JeffG 2013-07-04T11:31:45

In the ListView XML definition, add\n\nandroid:fastScrollEnabled=\"true\"\n\n\nor in code \n\nlistView.setFastScrollEnabled(true);\n\n\nCreate file fastscroll_thumb.xml in the res/drawable folder as follows:\n\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <item android:state_pressed=\"true\" android:drawable=\"@drawable/fastscroll_pressed\" />\n <item android:drawable=\"@drawable/fastscroll\" />\n</selector>\n\n\nIn AndroidManifest.xml, set a custom theme for your application:\n\n<application\n android:theme=\"@style/ApplicationTheme\"\n ...>\n\n\nCreate a values folder in the res folder. Create themes.xml files in res/values as follows:\n\n<resources>\n <style name=\"ApplicationTheme\">\n <item name=\"android:fastScrollThumbDrawable\">@drawable/fastscroll_thumb</item>\n </style>\n</resources>\n\n\nLastly make sure that fastscroll.png and fastscroll_pressed.png exist in your drawable folder",


TalkLittle 2012-04-22T06:59:38

Note that the android:fastScrollThumbDrawable attribute only applies for Android API Level 11 and later.\n\nhttp://developer.android.com/reference/android/R.attr.html",


ademar111190 2013-08-21T07:58:08

I'm using the android:fastScrollThumbDrawable but I not know why it isn't working, so searching on web i found here a hard code solution, I not know if it works on old API but in my case was solved the problem. Note I'm using API 18 like target and a device with API 17 to test.\n\nthe code:\n\ntry {\n Field f = AbsListView.class.getDeclaredField(\"mFastScroller\");\n f.setAccessible(true);\n Object o = f.get(<<your listView here>>);\n f = f.getType().getDeclaredField(\"mThumbDrawable\");\n f.setAccessible(true);\n Drawable drawable = (Drawable) f.get(o);\n drawable = getResources().getDrawable(R.drawable.<<your thumb drawable here can be a selector>>);\n f.set(o, drawable);\n} catch (Exception e) {\n e.printStackTrace();\n}\n",


JustinMorris 2014-03-05T22:24:49

In order to change the fastScrollThumbDrawable, the fastScrollTrackDrawable, or the text color of the fastscroll SectionIndexer you have to use a Context Theme. The other answers recommend overriding the application's theme via the AndroidManifest to do this. That does work but if you want different scrollbar appearances per ListView you can't do that. Also, the way you change the text color on SectionIndexer shouldn't be done in your app theme because it may have other undesired effects. \n\nThe best way to style a ListView for fastscrolling is to create a custom ListView that uses a ContextThemeWrapper. \n\nHere is an example:\n\npublic class FastscrollThemedListView extends ListView {\n public FastscrollThemedListView(Context context, AttributeSet attrs) {\n super(new ContextThemeWrapper(context, R.style.FastScrollTheme), attrs);\n }\n}\n\n\nThat is all you need. Your style will look like this:\n\n<style name=\"FastScrollTheme\">\n <item name=\"android:textColorPrimary\">?android:textColorPrimaryInverse</item>\n <item name=\"android:fastScrollThumbDrawable\">@drawable/fast_scrollbar_thumb</item>\n <item name=\"android:fastScrollTrackDrawable\">@drawable/fast_scrollbar_track</item>\n</style>\n\n\ntextColorPrimary is how you hook is how you hook into the SectionIndexer font color if you use it.\n\nYour ListView would look like this:\n\n<com.yourapp.view.FastscrollThemedListView\n android:id=\"@android:id/list\"\n android:layout_width=\"fill_parent\"\n android:layout_height=\"fill_parent\"\n android:drawSelectorOnTop=\"false\"\n android:cacheColorHint=\"@color/myWhite\"\n android:scrollbars=\"vertical\"\n android:scrollbarSize=\"12dip\"\n android:fastScrollEnabled=\"true\"/>\n",


More about “Android ListView fastScrollThumbDrawable not working” related questions

Android ListView fastScrollThumbDrawable not working

i am doing an app where i want the fastscroll tab on my listview to be a custom thumb tab. reading the docs online i thought this would do it: &lt;ListView android:id="@android:id/list" android:

Show Detail

Conditional compilation of fastScrollThumbDrawable?

I have an app with min API 10, and I set fastScrollEnabled to true. Now, the fastScrollThumbDrawable is really horrible, and I want to change it. I can add in the style.xml the line &lt;item name="

Show Detail

android listview fast scroll customization issue

here is my listview &lt;ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/ListView" android:fastScrollEnabled="true"

Show Detail

Android ListView transparent background not working

android:divider transparency is not working. Setting a color (e.g. #BBF232) is working fine. Using "@android:color/transparent" as listview background is working properly aswell. Just when using it...

Show Detail

Android ListView ClickEvent not working

I am using Custom ListView in Android and everything is working fine fetching data into list. Earlier the click event working fine with it but when I applied custom TextView and LinerLayout with a ...

Show Detail

Android clickable not working on listview

I want to use ripple effect for this I set to android:clickable="true" but when I do this onClick event is not working,but onLongClick is working.How can I resolve this ? If I don't set android:

Show Detail

Android ListView listSelector not working

I am trying to set a custom selector to a ListView. It's working fine on newer devices but not working on lower version of devices.I want the ListView selected item to be stay highlighted. Please ...

Show Detail

Android App - listView is not working

I'm new to Android App programming and tried to include a ListView to my Test-App but it's not working. I don't know if the ListView is invisible or not even initialized. The Activity Code: public

Show Detail

Show scroll only on touch Listview

I want to show scroll when the listview is touched and want to disappear when not touched irrespective of the number of items in a listview. This is what my current snippet looks like &lt;?xml

Show Detail

Android ListView selector not working well

`I am utilizing list selector, but its not working acoordingly. I am gettings effects after clicking list item, but there is no effect before item is clicked. Here is my code for selector: &lt;?xml

Show Detail