Android Application
Kotlin 고급 위젯 - 그 밖의 뷰 컨테이너(View Container) :웹뷰(WebView)
작성자 임베디드코리아
작성일23-09-24 03:35
조회2,009회
댓글0건
------------------------------------------------------------------------------------
activity_main.xml
-------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<WebView
android:id="@+id/webView"
android:layout_width="409dp"
android:layout_height="729dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
------------------------------------------------------------------------------------
MainActivity.kt
-------------------------------------------------------------------------------------
class MainActivity : AppCompatActivity() {
private var mBinding: ActivityMainBinding? = null
private val binding get() = mBinding!!
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var webview:WebView = findViewById(R.id.webView)
webview.apply {
webViewClient = WebViewClient()
settings.javaScriptEnabled = true
}
webview.loadUrl("https://m.naver.com")
}
}
------------------------------------------------------------------------------------
AndroidManifest.xml
-------------------------------------------------------------------------------------
<uses-permission android:name="android.permission.INTERNET"/>
------------------------------------------------------------------------------------
build.gradle.kts
-------------------------------------------------------------------------------------
android {
:
buildFeatures {
viewBinding = true
}
}