I am creating an Android Tutorial Application. I am planning to use Tabs to display the java and the xml code used for that topic.
I thought of using TextView and applying the Java and XML code as text to it.
However I am failing to format the Java code, plus I am not able to add xml as text at all as it has tags which are not supported.
Below are snaps from another App and the desired output is what I am looking for.
Any help or suggestions are welcomed.
You could display your Code in your TextView with HTML and style/format it with CSS.
Try this,
Suppose you have HTML code like this
<h2>Title</h2><br>
<p>description here</p>
Then in android you can use below code
TextView tvTrial=(TextView)findViewById(R.id.tvTrial);
String html="<h2>Title</h2><br> <p>description here</p>";
tvTrial.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
Now any thing you want to display in you view you can store it the string and set it.
Related
I saw this topic that tells me how to display HTML text in a TextView in Java. For example, if my TextView has "<small>Hello</small>" as its text and I used the code in that topic, I would see a small "Hello" in my TextView.
Now I want to reverse this. I want to get the HTML code of the TextView that I have enabled HTML format, i.e., I want to get "<small>Hello!</small>". Is there a way to do this?
I have tried tv.getText() (tv is the name of the TextView), but it instead returned "Hello", not as I had expected.
First I'm using Anko library, Kotlin, Java in my project.
I have an android app that test skills in French so I want to make a part of Textview editable its something like this (Solo Learn):
https://i.stack.imgur.com/bfric.png
I try :
je mang$ une pomme
then split String with $ and add editText in place of $ but it's not a good idea
using web view also it's not a good idea even its work
thanks in advance.
You can add addTextChangedListener to EditText view and add prefix or suffix, you need to be non-editable.
Check this previous question also ->
Put constant text inside EditText which should be non-editable - Android
In an application that I'm developing my goal would be to have highlighted code for some language, i.e. Java, and make so that some elements of code (functions, parameters) are clickable.
I understood that I need some js-based syntax highlighter capable to output raw html instead of linking a CSS stylesheet to the code.
What I still don't get is:
Is there any highlighter that ouputs highlighted code in such format?
How to make just some words clickable?
Is there any alternative to this strategy?
UPDATE1: As first attempt, I downloaded the source code of the android-codepad project, and edited the HTMLViewerPlusPlus class so that it highlights the HTML and, instead of showing it in a WebView, it shows it in a TextView, but since codepad uses css styling, I'm not getting the proper results. I'd need a new alternative that generates hard-styled html code.
UPDATE2: Using jsoup library with this method I managed to parse the code so that I get inline style attribute for each html element, but how to convert css styles to html tags?
I'm trying to convert BB code to HTML in Java for an Android project. An example of the text in which the bb code is embedded looks like this:
[b]This[/b] is some [url="http://www.example.com"]example[/url] text
to display my problem.
There also might be several paragraphs [i]of[/i] text and normal URLs http://www.example.com.
What it needs to look like in the TextView:
This is some example text to display my problem.
There also might be several paragraphs of text and normal URLs http://www.example.com.
Unfortunatly I don't have any code to show you since i don't know how to go about doing this. The only thing i can come up with now is making alot of regular expressions but i´m not sure if that would be the best solution.
Eventually this will all be displayed in an Android TextView.
Any help is appreciated!
There are some java BB-code libraries out there. Check this question for information on them.
I'm developing an ebook app for Android. when the text length given in string.xml is very large (around 500 words) it is not shown in the text view.
It took a while for me to figure this out. I have two text views and one is working propoerly as it is a small paragragh with 100 words but the secound TextView is larger and when the event is triggered it shows an empty screen.
Any char limitation in TextView?? wot would be the alternative?? Please help me.
Thanks in advance.
TextView doesn't sound like the correct component for your use. I would imagine you would get much better results using WebView.
You can define your content in HTML files instead of putting that much text into strings.xml.