Android - Questions about Edit Text in WebView - android

I'm using a Edit Text to put in a URL to search in the Internet. But to use a URL, I need to put http:// in front of the Url. Is there a way, to hide this and use it for default?
And the other thing is to have only one single line in the Edit Text?
Thanks

Is there a way, to hide this and use it for default?
When you retrieve the value from the EditText, see if it begins with a recognized scheme (e.g., https://). If not, add it yourself, through string concatenation or StringBuilder or something.
And the other thing is to have only one single line in the Edit Text?
Use android:maxLines="1" in the <EditText> element in your layout.

Related

Spaces between tags are ignored when rendering HTML to Flutter

Let’s say I have a function that receives a string that represents a text in HTML format and I want to show this text in Flutter. Some words in the text are supposed to be bold. If I have a few bold words in a row, the spaces between the tags are ignored. How can I show the text without it ignoring spaces?
For example if I use this code and wrap the text with the Html widget:
Html(data: "<b>hello</b> <b>world</b>"),
It shows helloworld but I want it to show hello world .
(If I don’t wrap it in Html the spaces are printed but I do need to render Html to a Flutter widget)
I would really appreciate your help.
Use a non-breaking space entity ( ).I don't know if it will work or not, but you should try this.
Html(data: "<b>hello</b> <b>world</b>"),
I ended up using this line and it worked:
Html(data: text.replaceAll("</b> <b>", "</b> <b>")),

How can I copy all visible text of a webView?

I have a webView that loads a page. How do I copy all visible text on the webView? I don't want the innerHTML. I want the visible text. In other words, I want the same text that can be achieved by "selecting all" and copying.
Use a HTML parser which can give you nodes under your body element and keep aggregating text present inside each node. You could use this https://jsoup.org/
as a parser, it is quite established.

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.

Android - Insert large text in an Activity

i need to create an activity with the description on an object.
This description is about 1000 characters, on 16 line.
I wanna ask if there is some way or some rule to follow to insert a string big like this in a textview in android?
I only have to format in in the values/string file or i have to do something else?
And in this description there are some link, how can make them clickable? (when i click i wanna open my browser with the link).
To make links clickable just add this to your view :
android:autoLink="web"
Yes you just need to add that text to resources.
Best wishes.
Put the string in strings.xml, set it to a text view inside a scroll view so that it doesn't get hidden on smaller screens, set autoLink to make the links clickable.

HTML/ASCII Symbols in TextView?

Is there a way to represent special HTML characters in a EditText in Android? I want to display symbols like section signs (§), bullet points (•), degrees (°), etc.
Is there a way to do this?
Thanks!
EDIT: The original post had asked about a TextView, but my intended question is about EditTexts. I want the user to be able to press the button corresponding to the symbol they want, and the symbol will be added to the EditText, and they then resume typing.
Have you tried \u00A7 \u2022 and \u00B0 in setText?
That are unicode numbers of those characters.
For EditText, you just have to create buttons with mEditText.getText().append(character) and probably mEditText.focus().
Have you looked at the Html.fromHtml(...) methods?
Alternatively you could just use a WebView instead of a TextView and use loadData(...) to load an HTML string.

Categories

Resources