简体   繁体   中英

Disable only Horizontal Scroll in Android Webview

I am Using a third party Library richeditor-android .

The Library is Great in it self and uses android web-view to provide text rich features. When you are done editing a text you can take it as a string and show it in the same Rich Editor's web-view after using

setInputEnabled(false)

But the problem is that web-view doesn't wrap text and instead enables horizontal scroll view for words longer than the screen.(The result is same with a normal web-view) I want the web-view to show the text in a similar pattern that it used to show it when I was editing the text.

I have Used everything mentioned in various answers available on stack overflow but no success yet. The main Problem is I want to disable only horizontal scroll while allow user to scroll vertically.

I have inserted images for example.

Image when I am entering the text.

在此处输入图片说明

Image when I am showing the Text.

在此处输入图片说明

Try the below code to remove the horizontal scroll using CSS.

Make a .css file in your assets folder, and paste the below code in that file.

.wrap {
    word-wrap:break-word;
}

After that in your Activity put the below code.

StringBuilder sb = new StringBuilder();
            sb.append("<HTML><HEAD><LINK href=\"justify.css\" type=\"text/css\" rel=\"stylesheet\"/></HEAD><body><div class=\"wrap\"> ");  //Justify.css is the name of the file in your assets folder
            sb.append("YOUR TEXT");
            sb.append("</div></body></HTML>");
            web_view.loadDataWithBaseURL("file:///android_asset/", sb.toString(), "text/html", "utf-8", null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM