WYSIWYG in Android webview

浪尽此生 提交于 2019-12-03 20:27:40

问题


I've been trying to offer a WYSIWYG HTML editor to my users, from inside my app. It doesn't have to be a fancy WYSIWYG. I just need basic functionality like Bold, Italic, Underline, images, link and some basic formatting (font size, colour, alignment). That should be enough.

The perfect solution would be an open source library, but I haven't been able to find one. So I googled around for a web-based editor that works on Android. I found Sceditor. This editor works great when I fire up my Android browser (Chrome beta). It SEEMS to work from my webview (see screenshot) as well, but it doesn't.

As soon as I run the editor from within the app, most functionality stops working. The cursor jumps around randomly, I cannot edit existing text anymore and more weird stuff happens. Basically, it just doesn't work.

Question: How can I get this to work appropriately?

Thanks a LOT in advance!


回答1:


EditText is perfectly capable of displaying rich text. It's just that there's no easy way for users -- or even developers -- to really control that formatting. Hence, I've been poking off and on with a library to deal with this, offering a RichEditText drop-in replacement for EditText. It's still a work-in-progress, and I really need to spend more time on it in the not-too-distant future.




回答2:


Webview of Andoird API support content editable of HTML.

webSettings.setJavaScriptEnabled(true)
webSettings.setDomStorageEnabled(true);
webSettings.setLightTouchEnabled(true);

to enable webview editable and then use

 webview.loadurl("javascript:....")

such as :webView.loadUrl("javascript:document.execCommand('bold', false, null);"); to control editing.

your can see WYSIWYG editing of my application on Android, WYSIWYG editing of YodaNote 0.4



来源:https://stackoverflow.com/questions/17114348/wysiwyg-in-android-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!