"Android" Custom ListView Quick Scroll bar

Source: Internet
Author: User

http://blog.csdn.net/xyang81/article/details/17680333

There's a post on EoE. Changing the icon of a quick slide block by reflecting, dynamically modifying the Mthumbdrawable property of the Fastscroller object is not an implementation, but the reflection is less efficient. The following describes how to customize icons using style.

As you can tell from the Init method of the Fastscroller class, Mthumbdrawable is by acquiring the current activity theme of Android. R.attr.fastscrollthumbdrawable Property Assignment, since this is the case, we can completely customize a theme that covers Android. The R.attr.fastscrollthumbdrawable property corresponds to the drawable not to be done!

1. Define a Theme

<style name= "Listviewfastscrollthumb" parent= "@android: Style/theme.light.notitlebar.fullscreen" > <item Name= "Android:fastscrollthumbdrawable" > @drawable/ic_launcher</item></style>

2, the current ListView activity app custom Theme

<activity android:name= "com.example.actionbardemo.MainActivity" android:label= "@string/app_name" Android:theme = "@style/listviewfastscrollthumb" > <intent-filter> <action android:name= "Android.intent.action.MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </INTENT-FILTER></ACTIVITY&G T

3. Verification

public class mainactivity extends  ListActivity {private static final int[] ATTRS = new int[]  {        android. r.attr.fastscrollthumbdrawable,    }; @Overrideprotected  void oncreate (Bundle  savedinstancestate)  {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Setlistadapter (New arrayadapter<string> (this, android. r.layout.simple_list_item_1, cheeses.scheesestrings));imageview imageview =  (ImageView)  findviewbyid (r.id.fastscrolldrawable); Theme theme = gettheme (); Typedarray a = theme.obtainstyledattributes (attrs);D rawable drawable =  A.getdrawable (0); imageview.setbackgrounddrawable (drawable);}} 

< Span style= "font-family:arial; font-size:18px; line-height:26px; Background-color:rgb (255, 255, 255); " > layout:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"     xmlns: tools= "Http://schemas.android.com/tools"     android:id= "@+id/container"      android:layout_width= "Match_parent"     android:layout_height= "Match_parent"      android:orientation= "Vertical"  >    <ImageView         android:id= "@+id/fastscrolldrawable"          android:layout_width= "Wrap_content"         android:layout_ height= "Wrap_content"  />    <ListView         android:id= "@android: Id/list"         android:layout_width= "match _parent "        android:layout_height=" Match_parent "       &Nbsp; android:fastscrollenabled= "true"          /></ Linearlayout>

Demo:http://download.csdn.net/detail/xyang81/6788411


"Android" Custom ListView Quick Scroll bar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.