进度条可以用于进行音量的调整 

xml属性

     android:max="100" 最大值是100 

     android:progress="30" 设置当前的值

java属性

      seekBar.setProgress(90); 设置当前的值

      seekBar.setMax(100); 设置最大值

      设置监听事件 

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                Log.d(TAG, "onProgressChanged:" + progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Log.d(TAG, "onStartTrackingTouch" + seekBar.getProgress());
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Log.d(TAG, "onStopTrackingTouch" + seekBar.getProgress());
            }
        });

java 代码

 SeekBar seekBar = findViewById(R.id.seekBar);

        seekBar.setProgress(90);
        seekBar.setMax(100);

        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                Log.d(TAG, "onProgressChanged:" + progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Log.d(TAG, "onStartTrackingTouch" + seekBar.getProgress());
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Log.d(TAG, "onStopTrackingTouch" + seekBar.getProgress());
            }
        });

xml代码

<SeekBar
        android:id="@+id/seekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="30"/>

posted on 2021-03-17 00:35  python我的最爱  阅读(684)  评论(0编辑  收藏  举报