액션버튼을 누르면 키보드가 내려감
android:imeOptions="actionDone"
리플 이펙트
android:background="?attr/selectableItemBackground"
drawable 리소스
<solid android:color="@color/light_gray"/> //색칠
<corners android:radius="16dp"/> //끝을 둥글게
주소와 웹 구분
android:elevation="4dp" //그림자로 띄워서 구분
android:background="@color/white" //원래는 투명하므로, 흰색처리
새로고침
gradle의 dependencies에 추가
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
webView를 refreshLayout에 넣어야함
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolBar">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
새로고침 표시 제거
inner class WebViewClient : android.webkit.WebViewClient() {//inner로 상위 클래스 접근가능
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
refreshLayout.isRefreshing = false
}
}
<uses-permission android:name="android.permission.INTERNET"/>
http로는 보안으로 인해 접근 못하지만, manifest에 밑 코드를 추가하면 됨
android:usesCleartextTraffic="true"
자바스크립트의 보안으로 인해 webView에 추가해야 사이트 기능을 이용할 수 있음
webView.settings.javaScriptEnabled = true (apply 적용)
webView.webViewClient = WebViewClient() // webView에 load하게 함
addressBar.setOnEditorActionListener { v, actionId, event ->//주소창 입력액션
if (actionId == EditorInfo.IME_ACTION_DONE) {//키보드가 닫히면
webView.loadUrl(v.text.toString())//해당 사이트로 이동
}
return@setOnEditorActionListener false //true를 반환하게된다면 액션을 진행할 수가 없어서 키보드가 안닫아짐
}
goBackButton.setOnClickListener {
webView.goBack()
}
앞 페이지로
goForwardButton.setOnClickListener {
webView.goForward()
}
override fun onBackPressed() {
if(webView.canGoBack()){ //이전 페이지가 있다면
webView.goBack()
}
else{ //없다면
super.onBackPressed() // 앱종료
}
}
companion object {
private const val DEFAULT_URL = "http://www.google.com"
}