Android Application
작성자 임베디드코리아
작성일23-10-16 22:37
조회1,548회
댓글0건
-------------------------------------------------------------------------------------
activity_main.xml
-------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/edtUrl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="URL을 입력하세요."
android:singleLine="true" >
</EditText>
<Button
android:id="@+id/btnGo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="이동" />
<Button
android:id="@+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="이전" />
</LinearLayout>
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" />
</LinearLayout>
------------------------------------------------------------------------------------
MainActivity.kt
------------------------------------------------------------------------------------
class MainActivity : AppCompatActivity() {
lateinit internal var edtUrl : EditText
lateinit internal var btnGo : Button
lateinit internal var btnBack : Button
lateinit internal var web : WebView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
getSupportActionBar()!!.setDisplayShowHomeEnabled(true)
getSupportActionBar()!!.setIcon(R.drawable.web)
edtUrl = findViewById<EditText>(R.id.edtUrl)
btnGo = findViewById<Button>(R.id.btnGo)
btnBack = findViewById<Button>(R.id.btnBack)
web = findViewById<WebView>(R.id.webView1)
web.webViewClient = CookWebViewClient()
var webSet = web.settings
webSet.builtInZoomControls = true
btnGo.setOnClickListener {
web.loadUrl(edtUrl.text.toString())
}
btnBack.setOnClickListener {
web.goBack()
}
}
class CookWebViewClient : WebViewClient1() {
@Deprecated("Deprecated in Java")
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
return super.shouldOverrideUrlLoading(view, url)
}
}
}
------------------------------------------------------------------------------------
*** AndroidManifest.xml
------------------------------------------------------------------------------------
<uses-permission android:name="android.permission.INTERNET"/>
<application
:
android:label="간단 웹브라우저"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"