wasup
Android) WebView 본문
반응형
WebView
웹브라우저는 구성하는 HTML과 같은 요소들을 받아들여 브라우저와 동일한 형식으로 해석해 보현해주는 뷰
: pc서버에서 응답한 웹 파일을 받아서 안드로이드에서 똑같이 보여주고, ios에서도 동일하게 동작.
: 디바이스에 상관 없이 정보 공유가 가능한 하리브리드 앱을 구현할 수 있게 도와줌.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.book11_web">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/emo_im_cool"
android:label="WebView TEST"
android:logo="@drawable/web"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
<activity
android:name=".MainActivity"
android:label="Simplr WebView"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<EditText
android:id="@+id/editUrl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Url 한줄로 입력"
android:singleLine="true"
/>
<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/webView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
/>
</LinearLayout>
MainActivity.java
package com.example.book11_web;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
//변수
EditText editUrl;
Button btnGo, btnBack;
WebView web;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.web);
editUrl = (EditText) findViewById(R.id.editUrl);
btnGo = (Button) findViewById(R.id.btnGo);
btnBack = (Button) findViewById(R.id.btnBack);
web = (WebView) findViewById(R.id.webView01);
btnGo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
web.loadUrl(editUrl.getText().toString());
}
});
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
web.goBack();
}
});
}//onCreate-end
//inner class
class CookWebViewClient extends WebViewClient{
public boolean shouldOverrideUrlLoading(WebView view, String url){
return super.shouldOverrideUrlLoading(view, url);
}
}
}//class-end
참고 링크 :
https://wiserloner.tistory.com/1351
반응형
'IT > Android' 카테고리의 다른 글
Android) Test (0) | 2021.08.14 |
---|---|
Android) 계산기 만들기 (0) | 2021.08.10 |
Android) ActionBar.TabListener (0) | 2021.08.07 |
Android) TabHost (0) | 2021.08.07 |
Android) ViewFlipper (xml + java) (0) | 2021.08.07 |
Comments