1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| package com.example.uidemo.activity;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.view.View; import android.widget.ProgressBar; import android.widget.SeekBar; import android.widget.TextView;
import com.example.uidemo.R;
import java.math.BigDecimal; import java.util.Locale;
public class ProgressBarActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
private SeekBar seekBar;
private ProgressBar progressBar1;
private ProgressBar progressBar2;
private TextView loadingText;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_progress_bar); seekBar=findViewById(R.id.seek_bar); progressBar1=findViewById(R.id.progress_bar1); progressBar2=findViewById(R.id.progress_bar2); loadingText=findViewById(R.id.loading_text); seekBar.setOnSeekBarChangeListener(this); }
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { String per=progress+"%"; if(progress==seekBar.getMax()){ loadingText.setText("加载完成"); progressBar1.setVisibility(View.GONE); }else{ loadingText.setText("正在加载中("+per+")"); progressBar1.setVisibility(View.VISIBLE); progressBar2.setProgress(progress); }
}
@Override public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override public void onStopTrackingTouch(SeekBar seekBar) { progressBar2.setProgress(seekBar.getProgress()); }
}
|