how to insert jpeg files in edittext android

☆樱花仙子☆ 提交于 2020-01-05 12:12:01

问题


Is there any way to add jpeg files to edittext in android. Basically i am creating a rich text editor in android which should have a provision to display images. Or do i need to make changes in edittext canvas for that. Any suggestions would be really helpful.

-Regards, Ron..


回答1:


Maybe you could use the android-richtexteditor component.

http://code.google.com/p/android-richtexteditor/

The code has been deleted from the official project but it is still available in the history.

http://android-richtexteditor.googlecode.com/svn-history/r3/trunk/




回答2:


EDIT: Sorry I did not take enough time to read. You wanted an Editable with picture, not a simple TextView.

Anyway, the solution is maybe to catch user keys and update a webview on the fly using

webview.loadUrl("javascript:onKeyDown("+keyCode+")");

You will need tight javascript/java linking. It can be somewhat tough to code but you will not be limited in terms of rich content.

Former answer:

You may want to use a WebView instead of a TextView.

They can be very lightweight if you feed them with simple HTML.

For example, if you want to use the image myImage.png that you stored in your project assets folder, simply use:

WebView myWebView = (WebView) findViewById(R.id.myWebView);
String richContent = "<html><body>This is text and an <b>Image</b>: <img src=\"file:///android_asset/myImage.png\" /></body></html>";
myWebview.loadData(richContent, "text/html", "utf-8");


来源:https://stackoverflow.com/questions/7579797/how-to-insert-jpeg-files-in-edittext-android

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