반응형
로딩바 예제
- Activity의 기본 레이아웃 영역(android.R.id.content)에 동적으로 생성 및 해제
로딩바 생성, 해제
void showLoading(Activity activity, boolean isShow) {
if(isShow) {
LinearLayout linear = new LinearLayout(activity);
linear.setTag("MyProgressBar");
linear.setGravity(Gravity.CENTER);
linear.setBackgroundColor(0x33000000);
ProgressBar progressBar = new ProgressBar(activity);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
progressBar.setLayoutParams(layoutParams);
linear.addView(progressBar);
linear.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) { /*클릭방지*/ }
});
FrameLayout rootView = activity.findViewById(android.R.id.content);
rootView.addView(linear);
} else {
FrameLayout rootView = activity.findViewById(android.R.id.content);
LinearLayout linear = rootView.findViewWithTag("MyProgressBar");
if(linear != null) {
rootView.removeView(linear);
}
}
}
사용
//Show
showLoading(MainActivity.this, true);
//Hide
showLoading(MainActivity.this, false);
반응형
'안드로이드' 카테고리의 다른 글
Android PDF Viewer(Assets, Http) (0) | 2021.11.17 |
---|---|
Android Animation(View Property) (0) | 2021.11.17 |
Android Thread, Timer, CountDownTimer (0) | 2021.11.14 |
Android Fragment (0) | 2021.11.14 |
Android ViewPager (0) | 2021.11.14 |
최근댓글