在已有的进度条下面怎么添加会动的小数点的百分率显示

public class MainActivity extends AppCompatActivity {
private ProgressBar progressBar;
private Timer timer;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button1 = (Button) findViewById(R.id.button_1);
final Button button2 = (Button) findViewById(R.id.button_2);
progressBar = (ProgressBar) findViewById(R.id.progress_bar);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String s1 = button1.getText().toString();
if (s1.equals("start")) {
button1.setText("stop");
}
if (s1.equals("stop")) {
button1.setText("start");
}
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int progress = progressBar.getProgress();
progress = 0;
progressBar.setProgress(progress);
}
});
timer = new Timer();
final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == 0) {
if (button1.getText().equals("stop")) {
int progress = progressBar.getProgress();
progress = progress + 1;
progressBar.setProgress(progress);
}
}
}
};
timer.schedule(new TimerTask() {
@Override
public void run() {
// (1) 使用handler发送消息
Message message=new Message();
message.what=0;
mHandler.sendMessage(message);
}
},0,100);
}
}

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问