如何在活动中单击按钮时带上进度条我在主要活动中有一个按钮,如果我单击按钮我想显示进度条我不想使用辅助活动为此我已完成2个活动但我需要在主要活动中完成它.
谢谢
我的代码:
家庭活动:
public void load(View v){
Intent intent = new Intent(this,Splash.class);
this.startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
启动活动:
public class Splash extends Activity {
private long ms = 0;
private long splashTime = 20000;
private boolean splashActive = true;
private boolean paused = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread mythread = new Thread() {
public void run() {
try {
while (splashActive && ms < splashTime) {
if (!paused)
ms = ms + 100;
sleep(100);
}
} catch (Exception e) {
} finally {
Intent intent = new Intent(Splash.this, Home.class);
startActivity(intent);
}
}
};
mythread.start();
}
}
Run Code Online (Sandbox Code Playgroud)
你可以这样做
ProgressDialog progress;
progress = new ProgressDialog(this);
progress.setTitle("Please Wait!!");
progress.setMessage("Wait!!");
progress.setCancelable(true);
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progress.show();
Run Code Online (Sandbox Code Playgroud)
将此代码称为您要显示的代码ProgressBar.
还有一种方法可以在按钮单击时显示 ProgressBar。
将此代码放在您的 xml 中
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible" />
Run Code Online (Sandbox Code Playgroud)
只需在 Java 文件中的 Button 单击上编写以下代码。
progressBar.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)
它将在您的 Button Click 上显示进度条。
| 归档时间: |
|
| 查看次数: |
19714 次 |
| 最近记录: |