0

In my android project, I have saved one HTML file inside my application. Now, from an Activity class I am using a webView to show the contents of this HTML file. This html file contains very long amount of text showing as a paragraph within paragraph tag.

So, in webView I can read the text by scrolling vertically. But I need a suggestion to show the entire content, page by page like a reader adjusting the mobile screen. More clearly, i don't want user to scroll vertically, rather user will swap right or left to move from one page to another.

Here's the Layout xml file code-

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ViewPagerActivity">


    <androidx.viewpager.widget.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <WebView
            android:id="@+id/webview_reader"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </androidx.viewpager.widget.ViewPager>

</androidx.constraintlayout.widget.ConstraintLayout>

And here's my Activity class code-

public class ViewPagerActivity extends AppCompatActivity {

    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_pager);

        webView = findViewById(R.id.webview_reader);

        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        webView.loadUrl("file://"+ViewPagerActivity.this.getFilesDir()+"/a.html");

    }
}

Here's the output of the app-

enter image description here]

I also tried to show the webview in Pageview but it also didn't work. So, I want this entire html page to divide the character by adjusting the mobile screen and show them page by page like a reader. So, it would be very nice if someone help me out this problem with coding example.

S. M. Asif
  • 3,437
  • 10
  • 34
  • 58
  • [Paginating text in Android](https://stackoverflow.com/a/32096884/3290339) might be useful. – Onik Apr 09 '20 at 13:57
  • But how can I use PagedTextView inside webView? – S. M. Asif Apr 13 '20 at 10:59
  • Of course you can't. I suggest to use `PagedTextView` instead, if applicable, w.r.t the `html` you have, I mean `Html.fromHtml(string)` has a limited `html / css` tags support – Onik Apr 13 '20 at 11:06
  • Or you might look at this old post: [HTML book-like pagination](https://stackoverflow.com/q/3636052/3290339) – Onik Apr 13 '20 at 11:08
  • One more note. Since you're using the `html` file locally stored, why not storing the text in a `txt` file instead? For reading text from a text file located in assets you might look at the Github sample app. – Onik Apr 13 '20 at 11:16

0 Answers0