💡 WebView가 로딩중일때만 ProgressBar 보여주기
...
<ProgressBar
android:id="@+id/progressBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/backToLastButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
...
// WebtoonWebViewClient 클래스
class WebtoonWebViewClient(private val progressBar: ProgressBar) : WebViewClient() { // WebViewClient()를 상속
// request에 따른 url loading 여부 리턴 ( false -> 로딩, true-> 로딩 x )
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
return false
}
// 페이지로딩이 끝날때
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
progressBar.visibility = View.GONE
}
// 페이지로딩이 시작될때
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
progressBar.visibility = View.VISIBLE
}![](https://velog.velcdn.com/images/mmihye/post/eeed30ef-2e72-431a-801c-73363f28d833/image.png)
}
// WebViewFragment.kt
binding.webView.webViewClient = WebtoonWebViewClient(binding.progressBar) //WebViewClient()