圆环进度条(默认)和水平进度条:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<!-- 圆环形进度条-->
<ProgressBar
android:id="@+id/pbCircle"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- 水平进度条-->
<ProgressBar
android:id="@+id/pbHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="点我" />
</LinearLayout>
设置和获取水平进度条进度:
package com.example.jiandanduihuakuang;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private ProgressBar pbHorizontal;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化控件
pbHorizontal = findViewById(R.id.pbCircle);
button = findViewById(R.id.button);
//按钮监听器
button.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//setProgress()设置进度条进度,getProgress获取进度条进度
pbHorizontal.setProgress(pbHorizontal.getProgress()+10);
}
});
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。