WebView android does not wrap the text - android

I've searched the Internet for a solution but I can't find it.
I have a WebView that display text, Just text. I want to wrap the text in the WebView, is that possible, or what?
And I want to make the user be able to select a certain text in the WebView and make him able to send the selected text by SMS, is that possible to?

I found the solution. You have to add some div tag on your web document, and then add a css class. I did this:
<div class="wrap">
with a css class like this:
.wrap {
word-wrap:break-word;
}

If the content in the WebView is something that you yourself have created or have control of, use a stylesheet optimized for mobile devices, or you can use jTouch or jQuery Mobile

If your content is literally plain text (no HTML markup), then the WebView will be treating it as preformatted text and won't wrap or insert linebreaks.
Try wrapping your text in an HTML wrapper:
<html><body>My text goes here</body></html>

Related

empty lines are missing in webview

Suppose Html body is having below content
qwweeerrt
asssdfghjjkl
zxxcvbnmm
It is shown like below :
qwweeerrtasssdfghjjklzxxcvbnmm
when I used
webView.loadData()
and
qwweeerrt asssdfghjjkl zxxcvbnmm when I used
webView.loadDataWithBaseURL()
So empty lines between qwweeerrt , asssdfghjjkl and zxxcvbnmm are missing in webview.
Please suggest me how to show the content as it is.
HTML (not the WebView itself) hates blanks.
Please use the <br/> tag to add a carriage return.
Double it, for an empty line.
If you want to add some blank spaces, use for each space you want.
Or, as an alternative, include your text in a
<pre>
Your multiline text here
Second line
Third line
</pre>
structure.
The WebView only renders the HTML (but also CSS and JavaScript).
And it does a great job.
I recommend you to study some HTML, if you plan to use a WebView in your app.
A great (and historically proven to be accurate) learning source is found here.
Your 'content' has to be more formatted. Proper way to show it would be like.
<p>qwweeerrt</p>
<p>asssdfghjjkl</p>
<p>zxxcvbnmm</p>
See what the webView.loadData() shows now.

Inverse/Reverse of Html.fromHtml(String)

I am creating a note application for myself. To style my notes, I write html tags, click a button and show styled version with html. from html.. But the problem is, I need to store the text with html tags not without it so when I get the data from the database, I get the text with style.
So I wonder is there any way to decode embedded html tags other than storing the string before html. from html function and acting accordingly? Also i can click the button anytime then continue typing which is very hard to track. Because i run this function to stylize ;
text.setText(Html.fromHtml(text.getText().toString()));
Which means i lose the tag info.
Thanks in advance.
If the user of the app write the html tags, the app should store them.
So as you suggest yourself, you will have to store the string before calling Html.fromHtml.

Dynamic html editor

My program works like this:
I have a WebView that loads assets/index.html. In this HTML I have the "Download Button", and am using Ajax to call a function to download HTML from a website. Then, the user has an option to open this downloaded HTML file inside the WebView (using the myWebView.loadUrl).
How can I make the user allowed to "edit" the HTML? I want them to be able to select text and edit the colour/font/background/bold/italic/etc. and then save and it update the HTML file with the edited text (probably with tags, <b><i>Edited Text</b></i> in the place of the normal edited text?
I think it is better to use JavaScript to do this, then when they click "Save", it calls a method to save and the next time the user clicks to "See the html in the WebView" it shows the styled text.
How can I do this? Maybe using JavaScript/jQuery text Editor like this (http://jqueryte.com/demos)?
I don't know about performance issues, since every time the user edits something the application will have to parse from file, show in WebView, edit, than write again full text to the file.
Can anyone offer some examples? directions? or better advice?
Add attribute contenteditable to your <body>
<body contenteditable='true'>
Now your <body> is editable.

The view is out of scope when displaying HTML in textview using fromhtml

I try to display a piece of HTML in a textview while the text is too long. When simply using Html.fromhtml, some text is out of scope. I thought adding <br/> tag to HTML is not a good way considering the resolution of each device is various. Is there a way to create line breaks automatically? Or, perhaps I could scroll the textview?
Any help would be appreciated.

Is there a way to store and display HTML with CSS to achieve text formatting in Android?

I'm creating a note taking app for Android and i would like the user to be able to format their text, i.e. bold, different text sizes.
What I would like to know is how can I do this bearing in mind the text will have to be store-able in a database.
Can i use a web view with a string of HTML i pull from the database and a custom defined CSS to style it on the user end?
I also know there is some sort of formatting class in Android but im unsure of how it work, im not convinced it would be easy to store the formatting information.
I think you should use Spannable text. See android.text.*. I think you should store the text in HTML markup. Also take a look at
http://developer.android.com/guide/faq/commontasks.html#selectingtext

Categories

Resources