SeekBar (1) personalized view of basic Android controls

Source: Internet
Author: User

The style of the SeekBar component provided by the system is too old to meet the needs of developers. Here we will introduce you to a simple and quick method for customizing your SeekBar style, so you don't have to rewrite it! 1. Prepare several personalized images. One is the drag background image, the other is the progress bar image, and the other is the drag bar image. Here are some examples:

: Drag the background image


: Progress bar chart
 
: Drag a chart
 

2. Create an xml file in the res/drawable directory. The configuration information is as follows: seekbar_progress.xml [html] <? Xml version = "1.0" encoding = "UTF-8"?> <Layer-list xmlns: android = "http://schemas.android.com/apk/res/android"> <item android: id = "@ android: id/background"> // background item <nine-patch android: src = "@ drawable/progress_background"/> // background image // use the 9 file here. Therefore, you can directly use the <drawable/> label if a common image is used for this configuration, or use the <shape/> label to customize the image </item> <item android: id = "@ android: id/progress "> // progress item <clip> <nine-patch android: src =" @ drawable/progress_progress "/> // progress chart </clip> </item> </Layer-list> 3. next, <SeekBar... /> Add the following parameters to the tag: [html] www.2cto. comandroid: progressDrawable = "@ drawable/seekbar_progress" android: thumb = "@ drawable/thumb_drawable". After completing the preceding three steps, you can easily implement the custom SeekBar view. Check the effect! Appendix: Here is an xml configuration file that uses the <shape/> label to set the background and progress for the SeekBar. Note that it is compared with the preceding 9 files: [html] <? Xml version = "1.0" encoding = "UTF-8"?> <! -- ChenJianLi Code: View: Seekbar sliding background effect --> <layer-list xmlns: android = "http://schemas.android.com/apk/res/android"> <! -- Background --> <item android: id = "@ android: id/background"> <shape> <corners android: radius = "5dip"/> <gradient android: startColor = "# ffffffff" android: centerColor = "# fffff0" android: centerY = "0.75" android: endColor = "# fffffafa" android: angle = "270"/> </shape> </item> <! -- Second progress bar --> <item android: id = "@ android: id/secondaryProgress"> <clip> <shape> <corners android: radius = "5dip"/> <gradient android: startColor = "#8000 cdcd" android: centerColor = "#8000 bfff" android: centerY = "0.75" android: endColor = "# a000b2ee" android: angle = "270"/> </shape> </clip> </item> <! -- First progress bar --> <item android: id = "@ android: id/progress"> <clip> <shape> <corners android: radius = "5dip"/> <gradient android: startColor = "# ff00ffff" android: centerColor = "# ff00ced1" android: centerY = "0.75" android: endColor = "# ff00f5ff" android: angle = "270"/> </shape> </clip> </item> </layer-list>

Related Article

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.