本文实例为大家分享了Android拖动条的具体代码,供大家参考,具体内容如下
activity_main.xml
<&#63;xml version="1.0" encoding="utf-8"&#63;>
MainActivity.java
package com.amy.seekbartest; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.SeekBar; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private SeekBar seekBar;//拖动条 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView result = (TextView) findViewById(R.id.textView1); seekBar = (SeekBar) findViewById(R.id.seekBar1); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { result.setText("当前值:"+progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { Toast.makeText(MainActivity.this,"开始滑动",Toast.LENGTH_SHORT).show(); } @Override public void onStopTrackingTouch(SeekBar seekBar) { Toast.makeText(MainActivity.this,"结束滑动",Toast.LENGTH_SHORT).show(); } }); } }
效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。