简体   繁体   English

在Android Webview中仅禁用水平滚动

[英]Disable only Horizontal Scroll in Android Webview

I am Using a third party Library richeditor-android . 我正在使用第三方库richeditor-android

The Library is Great in it self and uses android web-view to provide text rich features. 该库本身就是很棒的,并使用android网络视图提供了丰富的文本功能。 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 编辑完文本后,您可以将其作为字符串使用,并在使用后显示在同一Rich Editor的网络视图中

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. 但是问题是Web视图不包装文本,而是为水平于屏幕的单词启用水平滚动视图。(结果与普通Web视图相同)我希望Web视图以文本形式显示文本在编辑文本时使用过的相似模式。

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. 请尝试以下代码,以使用CSS删除水平滚动。

Make a .css file in your assets folder, and paste the below code in that file. 在您的资产文件夹中创建一个.css文件,然后将以下代码粘贴到该文件中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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