上一篇的ProgressBar练习是以Horizont的方式
这篇是以环形转圈圈的ProgressBar练习
利用按下Button後跳出Progress Bar,类似现在许多介面换页都会以ProgressBar显示
首先先在Activity_main.xml新增一个Login的Button
范例如下:
<?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"
android:orientation="vertical"
tools:context=".MainActivity" >
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="100dp"
android:text="LOGIN"
android:textSize="50dp" />
</LinearLayout>
接着在res/layout下新增一个xml档来设计按下Button後跳出Progress Bar的样式
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="100sp"
android:layout_height="100sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.41" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Loading..."
android:textSize="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/progressBar" />
</androidx.constraintlayout.widget.ConstraintLayout>
设计完Progress Bar後先新增一个java档来设定跳出的Progress Bar的时间
package com.example.itprogress2;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.LayoutInflater;
public class login {
private Activity activity;
private AlertDialog alertDialog;
login(Activity myactivity) {
activity = myactivity;
}
void startlogin(){
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
LayoutInflater inflater = activity.getLayoutInflater();
builder.setView(inflater.inflate(R.layout.in,null));
//等於true时滑鼠点一下即可暂停
//等於false时则不会暂停
builder.setCancelable(true);
alertDialog = builder.create();
alertDialog.show();
}
void dismisslogin(){
alertDialog.dismiss();
}
}
接着回到MainActivity.java来设定Button按下时的设定
package com.example.itprogress2;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button);
login login = new login(MainActivity.this);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
login.startlogin();
}
});
}
}
这样就好罗
<<: 只要有vscode和python就可以享受AWS上的服务
>>: Day 13:巢状路由的孩子-Nested Routes
回顾 终於来到最後一天,在挑战期间刚好Odoo15也发布了,也有新的Document,期间我们介绍了...
不知道大家有没有手冲咖啡的经验?如果没有的话,应该也看过或用过滤挂式咖啡,在冲咖啡时,水不能一次倒太...
前言 当我们要使用机器学习演算法来解决自然语言的问题,我们首先必须将文字进行量化( quantifi...
个人认为爬虫是网页技术,实用性前几名的。举凡股票价格抓取,104人力银行职缺,後台自动登入,591租...
对法国军事背景来自於网路上路过看到的世界十大着名雇佣兵组织,以及精奥兵团的印象,一个不问过去只收菁音...