Android开发 PorgressBar(进度条)的使用

圆环进度条(默认)和水平进度条:

Android开发 PorgressBar(进度条)的使用

<?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);
}
});
} }
上一篇:Android 自定义圆形旋转进度条,仿微博头像加载效果


下一篇:qW3xT.2,解决挖矿病毒。