My Android advanced tour ------> how to add a quick slider to the ListView component and modify the quick slider image, androidlistview
To use the layout file, you need to set android: fastScrollEnabled = "true", as shown in the following code:
<ListView android:id="@+id/listView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fastScrollEnabled="true" android:focusable="true" />
To use Java code, you must call the AbsListView. setFastScrollEnabled (boolean enabled) method. The following code is used:
ListView listView=new ListView(getApplicationContext()); listView.setFastScrollEnabled(true);
The ListView component does not provide an API for modifying the quick slider image. Therefore, you cannot directly modify the quick slider image. However, you can use the reflection technology to modify the slider image. The Code is as follows:
// FastScroller. the mThumbDrawable variable saves the quick slider image // you must first use the AbsListView. mFastScroller gets the FastScroller object Field = AbsListView. class. getDeclaredField ("mFastScroller"); field. setAccessible (true); Object object = field. get (listView); // get FastScroller. field = field. getType (). getDeclaredField ("mThumbDrawable"); field. setAccessible (true); // get FastScroller. the value of the mThumbDrawable variable Drawable drawable = (Drawable) field. get (object); // load the new slider object drawable = getResources (). getDrawable (R. drawable. img); // reset the field of the slider object. set (object, drawable); // you can specify the minimum number of fields. setAccessible (true); Field minPages = object. getClass (). getDeclaredField ("MIN_PAGES"); minPages. setAccessible (true); minPages. set (object, 1 );
========================================================== ========================================================== ============================
Author: Ouyang Peng: Welcome to repost. sharing with others is the source of progress!
Reprinted Please retain the original address: http://blog.csdn.net/ouyang_peng
========================================================== ========================================================== ============================
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.