i am receiving html from server and need to show it to user with simple styles (like bold, italic etc) and user should be able to edit it and impart similar style in it. i used webview, but it is not editable. I have seen some prev ques about rich text editor, but none of them are clear about what to do, or i could not understand as i am a newbie in this field. Thanks in advance. Here data is a string which is recieved from server, it contains html tags within. I need an editor which can add new text, edit prev one, bold/unbold selected text and some similar functions
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.setEnabled(true);
webView.loadDataWithBaseURL("file:///android_asset/", data, "text/html",
"utf-8", null);
Related
I want to implement a Rich text editor by using a webview in android. Content can be loaded by using a HTML file (which resides in assets) without any problem. But if user has edited the content of the webview (with all the formatting), I need to get the modified content as a HTML string and save it in the database. How can I do this?
I tried in many ways but it seems that we need to pass a URL to get the content of the webview. But after editing the webview content, how can we get the edited URL? or current updated webview content to HTML formatted string?
Using below code I made editable web view.
String msgBody = "<html>\n"+
"<body>\n"+
"<div id=\"content\" contenteditable=\"true\" style=\"font-family:Helvetica;font-size:14px\">" + a +" </div>\n"+
"</body>"+
"</html>";
// wbview = (WebView)this.findViewById(R.id.wbview);
wbView.getSettings().setJavaScriptEnabled(true);
wbView.loadDataWithBaseURL("", msgBody, "text/html", "UTF-8", "");
wbView.setHorizontalScrollBarEnabled(true);
wbView.setVerticalScrollBarEnabled(true);
In iOS we can get it easily by using below code line.
NSString* html=[_tbEmail.webView stringByEvaluatingJavaScriptFromString:#"document.getElementsByTagName('body')[0].innerHTML"];
I have been trying to set a bookmark in my webview text. But cant find any help regarding this. Please guide me how to do it
String html = "<html><head></head><body>"+text1+"</body></html>";
wv.loadDataWithBaseURL("", html, "text/html", "utf-8", "");
refer this project, in this browser he showed first page with most recent bookmarks and recent history. with help of html files and java.
https://github.com/darvin/zirco-browser
I have the URL of a webpage to be displayed into a webview in my Android app. Before showing this page i want to clear the html code of this page from some tag (such as the header, footer, ecc..) in order to show only few information. How can i do it? I tried to solve the issue working with JSoup but i can't understand how to create and pass the "new page" to the webview. Anybody can help me?
EDIT
I cleaned the html code useless through jsoup libraries. Then, always by mean of these, i get head and body content and finally i showing the "cleared" web page through these lines:
headURL = doc.select("head").outerHtml();
bodyURL = doc.select("body").outerHtml();
webview.loadData( "<html>"+headURL+bodyURL+"</html>" , "text/html", "charset=UTF-8");
webview.setWebViewClient(new DisPlayWebPageActivityClient());
The view shows the new page but do not load css files specified in the head(that has not been touched). Who can say me why?
You can fetch the WebPage you want to display as a string, parse and remove whatever you don't want and then load this string as data in your webview.
Something like:
String webContent = fetchPage(url);
String cleanedWebContent = cleanUp(webContent);
webView.loadData(cleanedWebContent, "text/html", "UTF-8");
Of course, you will need to implement fetchPage and cleanUp as they are not Android methods
first time question here.
So, I am uploading text to a WebView, in order to use the <p align = "justify">.
However, I am also trying to indent every first line of every chapter using for the spaces. But the indents don't always match, some have three spaces, some four, etc... I've tried using <pre>, &xa0; but to no avail.
My code is as follows:
webView2 = (WebView) findViewById(R.id.webView);
text ="<font color=\"#2C2C2C\"><html><body><p align=\"justify\"> TextTextTextText<br>" +
" MoreTextTextText</p></body></html></font>";
text2.loadData(text, "text/html", "utf-8");
I have a locally stored HTML file in my assets folder that I am accessing through this:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Global.setUpButton(this);
WebView webView = new WebView(this);
setContentView(webView);
//Sets up the settings for the webView
webView.loadUrl("file:///android_asset/map.html");
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.setInitialScale(0);
}
I was wondering if there is any way I would be able to view and/or edit the source of the HTML file loaded, as I may need to manipulate certain elements.
I found a workaround instead.
Created a JavascriptInterface that will allow me to append any HTML tags I need to. This is easier because I won't have to reload the page, which reduces loading time.
Sure. You create a layout with an EditText box, you load the file and display it in the box, then after editing, you store the new string in the file.
added:
You can use AssetManager to read the data as a String from the URL. Then you put the string in the EditText. Then the user edits it. Then you get the edited html from the editText, and do what you wanted to do with it in the first place. If I understand your questions correctly.