How to display Html content page using web browser in Android?

Hi, I am creating a simple application to display an html page in a webview. I am using webview and showing page load time like this.

Display first time load the data

After that, turn off the scroll and use the next and previous buttons to save back and forth. So my code is below.

The first onCreate screen adds a webview and loads an html file.

mainWebView = (WebView) findViewById(R.id.mainWebView); mainWebView.setVerticalScrollBarEnabled(false); mainWebView.setHorizontalScrollBarEnabled(false); mainWebView.getSettings().setJavaScriptEnabled(true); mainWebView.setWebViewClient(new MyWebClient()); mainWebView.setPictureListener(new MyPictureClass()); mainWebView.loadUrl("file:///android_asset/chapter-001.html"); 

after using the MyWebclient class to get the height and width for mainwebview.

 class MyWebClient extends WebViewClient { @Override public void onPageFinished(WebView view, String url) { System.err.println("Page Finish Call"); lanscapHeight = protraitHeight = findHeight = mainWebView.getHeight(); System.err.println("Find Height->"+findHeight); System.err.println("Portait Height->"+protraitHeight); System.err.println("Landscap Height->"+lanscapHeight); } } 

after that use myPictureClass to get a webView with a length.

 class MyPictureClass implements PictureListener { @Override public void onNewPicture(WebView view, Picture picture) { proTraitContain = mainWebView.getContentHeight(); System.err.println("picture Class Call-->"+proTraitContain); } } 

thereafter. Create the next and previous buttons to display the next and previous page. Use the SimpleOnGestureListener app to detect touch.

  btnNext = (Button) findViewById(R.id.btnNext); btnNext.setOnTouchListener(this); btnPrev = (Button) findViewById(R.id.btnPrev); btnPrev.setOnTouchListener(this); 

Cancel the touch method.

  @Override public boolean onTouch(View view, MotionEvent event) { if (view == btnNext) { btnClickFlage = true; gestureDetector.onTouchEvent(event); } else { btnClickFlage = false; gestureDetector.onTouchEvent(event); } return false; } implement the SimpleGestureListener class as Below. class MyGesture extends SimpleOnGestureListener { @Override public boolean onSingleTapUp(MotionEvent e) { super.onSingleTapUp(e); System.err.println("Display Total Contain For Protrait -->"+proTraitContain); System.err.println("Before Height-->" + findHeight); if (btnClickFlage) { if (findHeight > (proTraitContain+protraitHeight)) { if(restProtraitFlag) { System.err.println("If part In side Flag-->"+findHeight); findHeight=findHeight+protraitHeight; restProtraitFlag=false; //findHeight=findHeight+protraitHeight; mainWebView.scrollTo(0, findHeight); System.err.println("If part In side Flag-->"+findHeight); }else { mainWebView.loadUrl("file:///android_asset/chapter-002.html"); restProtraitFlag=true; } } else { if(protraitFlag) { if(findHeight==protraitHeight) { findHeight = protraitHeight; }else { findHeight = findHeight + protraitHeight; } protraitFlag=false; }else { findHeight = findHeight + protraitHeight; } mainWebView.scrollTo(0, findHeight); } } else { restProtraitFlag=true; if (findHeight<=0) { mainWebView.loadUrl("file:///android_asset/chapter-001.html"); System.err.println("Load Previous page"); } else { findHeight = findHeight - protraitHeight; mainWebView.scrollTo(0, findHeight); } } System.err.println("After Height-->" + findHeight); } return true; } } 

but I cannot show the last page of the current html page. Now what to do. any solution please give. I understand the width of the content correctly and use the scrollTo method to display, but I cannot do this. After the last page of the remainder of some of them can not be displayed.

Please saw me anyway.

Thanks in advance.

+6
source share
3 answers

Hello friends. Finally, I got my answer.i question. I use the ScrollTo method to scroll through the contents and display the next contents of the current page. But the problem is that webView Display all contains the corresponding device. All the time contains a display higher than this current value.so I use the Webview.getScale(); method Webview.getScale(); to display how widely used webview. Accordingly, I use this method and get current web browsing information and use the wise.it s finally it display page for me.

Name for Calendar Authentication De

+1
source

Hello. You have to put your HTML in res, and then in that you need to save it in raw after you can access it like this ...

webviewTips.loadUrl ("File: ///android_res/raw/tips.html");

0
source

You show a web page stored in a folder with your assets or from an SD card.

So, I advise you to leave this approach and this way to show the web page to the user.

And edit your HTML files and put Anchor Tags in it ... using the fact that the user can easily navigate the web page. ( Example for this )

0
source

Source: https://habr.com/ru/post/923174/


All Articles