Android
943. (Android/Xml) 안드로이드 웹뷰 SwipeRefreshLayout 및 ProgressBar 사용해 웹뷰 갱신 및 커스텀 로딩 프로그레스 생성
투케이2K
2025. 1. 22. 19:51
[개발 환경 설정]
개발 툴 : AndroidStudio
개발 언어 : Java / Kotlin
[소스 코드]
// --------------------------------------------------------------------------------------
[개발 및 테스트 환경]
// --------------------------------------------------------------------------------------
- 언어 : Java / Kotlin
- 개발 툴 : AndroidStudio
- 기술 구분 : Webview / Xml / Loading
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
[사전) 필요 설정]
// --------------------------------------------------------------------------------------
/**
* // -------------------------------------------------------
* 1. AndroidManifest.xml 파일 필요 퍼미션 :
*
* <uses-permission android:name="android.permission.INTERNET"/>
* <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
* <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
* // -------------------------------------------------------
* 2. 참고 사이트 :
*
* https://blog.naver.com/kkh0977/222680670897
*
* https://blog.naver.com/kkh0977/223491102945?trackingCode=blog_bloghome_searchlist
*
* https://blog.naver.com/kkh0977/223170502193?trackingCode=blog_bloghome_searchlist
* // -------------------------------------------------------
* */
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
[소스 코드]
// --------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
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"
android:id="@+id/refreshLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- [컴포넌트 : 웹뷰 : 전체 화면 지정] -->
<WebView
android:id="@+id/main_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#343d46" />
<!-- ------------------------------------------ -->
<!-- [컴포넌트 : 원형 프로그레스 : 웹뷰 위에 표시] -->
<!-- ------------------------------------------ -->
<!-- [android:layout_alignParent 속성을 사용해서 가운데 위치 정렬] -->
<!-- ------------------------------------------ -->
<!-- [android:background="#66000000" : 검정색 배경 투명도 40 퍼센트 설정] -->
<!-- ------------------------------------------ -->
<RelativeLayout
android:id="@+id/loadingBar"
android:layout_width="80dp"
android:layout_height="80dp"
android:gravity="center"
android:layout_centerInParent="true"
android:orientation="vertical"
android:background="#66000000">
<!-- [indeterminateTint : 원형 프로그레스 색상 변경 실시] -->
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminateTint="#a7eeff"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"/>
<!-- [닫기 가능 여부 표시 위해 텍스트 지정] -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="close"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="12dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"/>
</RelativeLayout>
</RelativeLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
[참고 사이트]
// --------------------------------------------------------------------------------------
// [안드로이드 웹뷰 유틸 파일]
https://blog.naver.com/kkh0977/222680670897
// [안드로이드 RelativeLayout 사용해 웹뷰에 커스텀 로딩 프로그레스 생성]
https://blog.naver.com/kkh0977/223491102945?trackingCode=blog_bloghome_searchlist
// [SwipeRefreshLayout 사용해 웹뷰 새로 고침 상태 갱신 수행 실시]
https://blog.naver.com/kkh0977/223170502193?trackingCode=blog_bloghome_searchlist
// --------------------------------------------------------------------------------------
반응형