Seekbar of common Android components

Source: Internet
Author: User

The Seekbar component is a drag bar that you can manually adjust the progress of, the most common place to use is to listen to music or watch video, move forward or backward to locate, volume control in your phone, etc.

In this instance, the progress is manually changed and the corresponding progress percentage is displayed in the TextView component.

The first is the layout file:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"     xmlns: tools= "Http://schemas.android.com/tools"     android:id= "@+id/linearlayout1"      android:layout_width= "Match_parent"     android:layout_height= "Match_parent"     android:orientation= "vertical"     tools:context= "com.example.test_ Seekbar. Mainactivity " >        <TextView         android:id= "@+id/textview1"         android: Layout_width= "Wrap_content"         android:layout_height= "wrap_content "        android:text=" @string/tv1 "         android:textappearance= "Android:attr/textappearancelarge"  />         <seekbar        android:id= "@+id/seekBar1"          android:layout_width= "Match_parent"          android:layout_height= "Wrap_content"         android:max= "100"         android:background= "#fff0f000"  />        <!-- android:max= "100" to set the maximum display value of the progress bar  --></LinearLayout>

Next is the Strings.xml file:

<?xml version= "1.0" encoding= "Utf-8"?><resources> <string name= "App_name" >test_seekbar</ string> <string name= "action_settings" >Settings</string> <string name= "TV1" >none</string& Gt;</resources>

Again is the Andorid source file:

package com.example.test_seekbar;import android.os.bundle;import  android.support.v7.app.actionbaractivity;import android.widget.seekbar;import  android.widget.seekbar.onseekbarchangelistener;import android.widget.textview;public class  mainactivity extends actionbaractivity implements onseekbarchangelistener{//Listening events for drag bars via interfaces     private textview textview=null;    private seekbar  seekBar=null;         @Override     protected  void oncreate (bundle savedinstancestate)  {         super.oncreate (savedinstancestate);         setcontentview ( R.layout.activity_main);                 textView =  (TextView)  findviewbyid (r.id.textview1);         seekbar =  (SeekBar)  findviewbyid (R.ID.SEEKBAR1);                  Seekbar.setonseekbarchangelistener (mainactivity.this);     }    @ Override    public void onprogresschanged (SEEKBAR&NBSP;ARG0,&NBSP;INT&NBSP;ARG1, &NBSP;BOOLEAN&NBSP;ARG2)  {//executes the method when the progress value changes         // todo  auto-generated method stub        textview.settext (" Current progress: "+string.valueof (arg1) +"% ");    }     @Override      public void onstarttrackingtouch (seekbar arg0)  {//Perform this method when you touch the drag bar          // TODO Auto-generated method stub            &nbSP;}      @Override     public void onstoptrackingtouch (SeekBar &NBSP;ARG0)  {//Execute this method when you leave the touch drag bar         // TODO  auto-generated method stub            }}

Finally, the test results are as follows:

Seekbar of common Android components

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.