In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Studio to achieve progress bar in Android, the article is very detailed, has a certain reference value, interested friends must read it!
XML code
Java code
package com.example.a18101352;import androidx.annotation.NonNull;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.widget.ProgressBar;import java.util.Random;public class MainActivity extends AppCompatActivity { private ProgressBar progressBar; private int maxProgress; private int currentProgress = 0; private Handler mHandler = new Handler(){ /** * Subclasses must implement this to receive messages. * * @param msg */ @Override public void handleMessage(@NonNull Message msg) { super.handleMessage(msg); switch (msg.what){ case 0: progressBar.setProgress(currentProgress); break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_progress_bar); progressBar = findViewById(R.id.pb_determinate); maxProgress = progressBar.getMax(); } @Override protected void onStart(){ super.onStart(); new Thread() { private Random random; @Override public void run(){ while(true){ try { for(int i = 0; i
< maxProgress; ++i){ //间隔一秒 Thread.sleep(1000); random = new Random();// currentProgress += 10;// if(currentProgress >maxProgress){// break;// } //Get a random number to currentProgress and display it currentProgress = random.nextInt(100); mHandler.sendEmptyMessage(0); } } catch (InterruptedException e){ e.printStackTrace(); } } } }.start(); }}
Thread in the for loop can be removed, loop is the test timing lengthened progress bar design.
That's all for "How to use Studio to implement progress bars in Android." Thanks for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.