how to limit seekbar

前端 未结 6 590
别那么骄傲
别那么骄傲 2020-12-29 02:10

I\'d like to set max and minimum limits of SeekBar to 50 and 20 respectively.

SeekBar has a direct option top provide max value, but how to set its

6条回答
  •  离开以前
    2020-12-29 02:49

    For example;

     public static int LENGTH_MIN_VALUE = 20;
     public static int LENGTH_MAX_VALUE = 50;
     SeekBar seekBar = (SeekBar) findViewById(R.id.passwordSeekBar);
        seekBar.setMax(LENGTH_MAX_VALUE);
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if(progress <= Constract.PASSWORD_LENGTH_MIN_VALUE){
                    progress = Constract.PASSWORD_LENGTH_MIN_VALUE + progress;
                }
    
                String numberAsString = String.valueOf(progress);
                seekNumberView.setText(numberAsString);
            }
    
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {}
    
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {}
        });
    

提交回复
热议问题