티스토리 뷰

반응형

Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.

Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.

 

아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

Load HTML file into WebView

HTML 파일 WebView에 로드하기

 문제 내용 

I have a local html page along with several other resources pointed by it (css files and Javascript libraries) that I would like to load into a WebView . How could this be achieved ?

저는 웹뷰에 로드하고 싶은 몇몇 다른 리소스(css 파일 및 Javascript 라이브러리)와 함께 로컬 html 페이지를 가지고 있습니다. 어떻게 이것을 달성할 수 있을까요?

 

Perhaps not the best way to procede but I'm still experimenting.

아마도 절차를 밟는 가장 좋은 방법은 아니지만 저는 여전히 실험 중이다.

 

 

 

 높은 점수를 받은 Solution 

The easiest way would probably be to put your web resources into the assets folder then call:

가장 쉬운 방법은 웹 리소스를 assets 폴더에 넣은 후 다음을 호출하는 것입니다.
webView.loadUrl("file:///android_asset/filename.html");

 

For Complete Communication between Java and Webview See This

Java와 Webview 간의 완벽한 통신은 다음을 참조하십시오.

 

Update: The assets folder is usually the following folder: <project>/src/main/assets This can be changed in the asset folder configuration setting in your <app>.iml file as:

업데이트: assets 폴더는 일반적으로 다음 폴더입니다: <project>/src/main/assets
<app>.iml 파일의 설정을 통해 asset 폴더를 변경할 수 있습니다.

 

<option name=”ASSETS_FOLDER_RELATIVE_PATH” value=”/src/main/assets” /> See Article Where to place the assets folder in Android Studio

<option name=”ASSETS_FOLDER_RELATIVE_PATH” value=”/src/main/assets” /> 기사 Android Studio에서 자산 폴더를 배치할 위치를 참조하십시오.

 

 

 

 가장 최근 달린 Solution 

probably this sample could help:

이 샘플이 도움이 될 수 있습니다.
  WebView lWebView = (WebView)findViewById(R.id.webView);
  File lFile = new File(Environment.getExternalStorageDirectory() + "<FOLDER_PATH_TO_FILE>/<FILE_NAME>");
  lWebView.loadUrl("file:///" + lFile.getAbsolutePath());

 

 

출처 : https://stackoverflow.com/questions/5749569/load-html-file-into-webview

반응형
댓글
공지사항
최근에 올라온 글