-
안드로이드 webview 웹뷰 사용법program_language 및 궁금한것/Android Studio 2018. 7. 29. 17:46
<uses-permission android:name="android.permission.INTERNET"/>
이걸 Mainfast에 써줘야지 인터넷 웹뷰가 사용가능하다.
이 권한을 부여안해준다면 err_cache_miss란 에러가 뜬다 꼭. 꼭. 추가하도록
<?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:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><RelativeLayoutandroid:id="@+id/top_layout"android:layout_width="match_parent"android:layout_height="wrap_content"><EditTextandroid:id="@+id/et_url"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_toLeftOf="@id/btn_move"android:text="http://google.co.kr" /><Buttonandroid:id="@+id/btn_move"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:text="이동" /></RelativeLayout><RelativeLayoutandroid:id="@+id/middle_layout"android:layout_above="@id/bottom_layout"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@+id/top_layout"><WebViewandroid:id="@+id/webview"android:layout_width="match_parent"android:layout_height="match_parent" /></RelativeLayout><RelativeLayoutandroid:id="@+id/bottom_layout"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:gravity="center"><Buttonandroid:id="@+id/btn_back"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Back" /><Buttonandroid:id="@+id/btn_forward"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="forward"android:layout_toRightOf="@id/btn_back"/></RelativeLayout></RelativeLayout>package com.example.webview;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.webkit.WebSettings;import android.webkit.WebView;import android.webkit.WebViewClient;import android.widget.Button;import android.widget.EditText;public class MainActivity extends AppCompatActivity implements View.OnClickListener {private EditText et_url;private Button btn_move, btn_back, btn_forward;private WebView webview;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);et_url = findViewById(R.id.et_url);btn_move = findViewById(R.id.btn_move);btn_back = findViewById(R.id.btn_back);btn_forward = findViewById(R.id.btn_forward);webview = findViewById(R.id.webview);// 이벤트 장착webview.setWebViewClient(new MyBrowser());WebSettings settings = webview.getSettings();settings.setJavaScriptEnabled(true);settings.setBuiltInZoomControls(true);btn_move.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {String url = et_url.getText().toString();if (url != null && url.length() > 0) {webview.loadUrl(url);}}});}// oncreate closeprivate class MyBrowser extends WebViewClient {@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url) {view.loadUrl(url);return true;}}@Overridepublic void onClick(View v) {}}모두의 게시판 이걸로 만들면되! 바부야.반응형'program_language 및 궁금한것 > Android Studio' 카테고리의 다른 글
안드로이드 뒤로가기키 비활성화 setEnabled (0) 2018.08.01 안드로이드 4대 컴포넌트 (0) 2018.07.29 안드로이드 하이브리드앱, 웹앱, 네이티브앱 차이점 (0) 2018.07.29 안드로이드 autocomplete 자동완성 (0) 2018.07.29 안드로이드 리스트뷰(ListView) (0) 2018.07.29