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-
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.