Android 프로그레스바 사용하기
package com.example.sampleprogress1;
import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
@BindView(R.id.progressBar)
ProgressBar progressBar;
@BindView(R.id.button)
Button button;
@BindView(R.id.button2)
Button button2;
ProgressDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
progressBar.setIndeterminate(false);
progressBar.setProgress(80);
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
dialog = new ProgressDialog(MainActivity.this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setMessage("데이터를 확인하는 중입니다.");
dialog.show();
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (dialog != null) {
dialog.dismiss();
}
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="80"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="보여주기" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="닫기" />
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
'안드로이드 앱프로그래밍 연습' 카테고리의 다른 글
Android 레이아웃 인플레이션 이해하기 (0) | 2019.07.17 |
---|---|
Android 시크바와 프로그레스바 보여주기 (0) | 2019.07.12 |
Android AlertDialog 알림 대화상자 보여주기 (0) | 2019.07.12 |
Android Toast 토스트,스낵바 그리고 대화상자 사용하기 (0) | 2019.07.12 |
터치 제스처 키 이벤트 처리하기 연습 (0) | 2019.07.09 |