Android base Control Seekbar use of drag bars

Source: Internet
Author: User

1. Introduction

Seekbar inherits ProgressBar, related attributes, and three triggering methods in different states:

        <!--<SeekBar-->            <!--android:layout_width= "Match_parent"-            <!--android:layout_height = "Wrap_content"-            <!--android:max= "up"-            <!--android:progress= "+"-            <!-- Android:id= "@+id/seekbar"-            <!--Android:thumb= "@mipmap/ic_launcher_round"/>-->// Set the slider's
Seekbar.setonseekbarchangelistener (NewSeekbar.onseekbarchangelistener () {@Override//progress has changed             Public voidOnprogresschanged (SeekBar SeekBar,intIBooleanb) {} @Override//Press the             Public voidOnstarttrackingtouch (SeekBar SeekBar) {} @Override//Let go             Public voidOnstoptrackingtouch (SeekBar SeekBar) {}});

2. Easy to use

This is a simple custom seekbar, light green is the progress bar color, red is a level two progress bar color, yellow is the background color!

Selector files for sliders:

<?XML version= "1.0" encoding= "Utf-8"?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android">    <Itemandroid:state_pressed= "true"android:drawable= "@drawable/seekbar_thumb_pressed" />    <Itemandroid:state_pressed= "false"android:drawable= "@drawable/seekbar_thumb_normal"/></selector>

progress bar Color Layer-list file: A list of graphics created by Layer-list, which is a drawable graphic.

<?XML version= "1.0" encoding= "Utf-8"?><layer-listxmlns:android= "Http://schemas.android.com/apk/res/android">    <ItemAndroid:id= "@android: Id/background">        <Shape>            <SolidAndroid:color= "#FFFFD042" />        </Shape>    </Item>    <ItemAndroid:id= "@android: id/secondaryprogress">        <Clip>            <Shape>                <SolidAndroid:color= "#f23f21" />            </Shape>        </Clip>    </Item>    <ItemAndroid:id= "@android: id/progress">        <Clip>            <Shape>                <SolidAndroid:color= "#FF96E85D" />            </Shape>        </Clip>    </Item></layer-list>

Overall XML layout file:

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:gravity= "Center"android:orientation= "vertical"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context=". Loginactivity ">        <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Current progress value:"Android:id= "@+id/textview"/>        <SeekBarAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:id= "@+id/seekbar"android:progress= "+"android:secondaryprogress= " the"Android:maxheight= "5DP"Android:minheight= "5DP"android:progressdrawable= "@drawable/sb_bar"Android:thumb= "@drawable/sb_thumb"/></LinearLayout>

Three types of state events triggered by Java files:

 Public classLoginactivityextendsappcompatactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_login); //Set up the login form.SeekBar SeekBar=(SeekBar) Findviewbyid (R.id.seekbar); FinalTextView TextView =(TextView) Findviewbyid (R.id.textview); Seekbar.setonseekbarchangelistener (NewSeekbar.onseekbarchangelistener () {@Override//progress has changed             Public voidOnprogresschanged (SeekBar SeekBar,intIBooleanb) {Textview.settext ("Current progress value:" +i); } @Override//Press the             Public voidOnstarttrackingtouch (SeekBar SeekBar) {toast.maketext (loginactivity. This, "Press", Toast.length_short). Show (); } @Override//Let go             Public voidOnstoptrackingtouch (SeekBar SeekBar) {toast.maketext (loginactivity. This, "Let Go", Toast.length_short). Show ();    }        }); }}

Android base Control Seekbar use of drag bars

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.