티스토리 뷰
안드로이드 웹뷰(webview) 만들기
AndroidManifest.xml
<uses-permission android:name="android.permission.Internet"/> 추가
인터넷을 사용하겠다는 권한
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 |
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dongshik.dscompany">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest> |
cs |
res하위 activity_main.xml 에
WebView 추가
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webview"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
activity_main.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 |
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.dongshik.dscompany.MainActivity">
<!--추가한 부분-->
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webview"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<!--추가한 부분 끝-->
</RelativeLayout>
|
cs |
마지막으로 MainActivity
1. WebKit 패키지 임포트!!!
import. android.webkit.WebSettings;
....
2. 웹뷰 선언
private WebView myWebView;
private WebSettings myWebSettings;
3. 변수에 웹뷰, 웹뷰설정 인스턴스 가져오기
myWebView = (WebView)findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
myWebSettings = myWebView.getSettings();
4. 여러가지 설정 변경 하단은 자바스크립트 사용여부 ture, false값
자바스크립트 사용여부 설정 이외에도 많은 설정메소드가 있다. 찾아보면 금방나오는듯.
myWebSettings.setJavaScriptEnabled(true);
5. 웹뷰에 원하는 페이지 로드
myWebView.loadUrl(http://www.naver.com);
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 |
package com.example.dongshik.dscompany;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView myWebView;
private WebSettings myWebSettings;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView)findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
myWebSettings = myWebView.getSettings();
myWebSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.naver.com");
}
} |
cs |
'개발 > Android' 카테고리의 다른 글
안드로이드 배포용 APK 생성 방법 및 사인 키 생성 (0) | 2018.04.24 |
---|---|
안드로이드 AVD 생성방법 (1) | 2018.04.24 |
Android Studio SDK 설정방법 (0) | 2018.04.24 |
Android Studio 설치 (0) | 2018.04.24 |
GCM 설명 및 구현 (0) | 2018.02.24 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 딥러닝 gpu 사용량
- 생활속탄소저감 #감탄캠페인 #나는 오늘도 감탄을 했다 #에코한림
- 전경추출
- Android Studio 키
- Django
- 엘리먼트삭제
- Java
- SET CHAINED OFF
- django 웹서버
- 파이토치 gpu 사용량
- 딥러닝 GPU #pytorch gpu
- 안드로이드 사인키
- 장고앱
- 장고프로젝트
- 안드로이드 키
- 파이토치
- 노드삭제
- gpu사용량
- 이미지 배경제거
- pytorch GPU
- unchained transaction mode
- django app
- removeNode()
- 이미지 전처리
- 이미지전처리
- 한림대의료원#친환경캠페인#감탄캠페인#종이 절약#에코한림
- removeNode
- 딥러닝 gpu 설정
- Grabcut
- sp_procxmode#
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함