How could I easily display a custom text without too many TextViews - android

For example, doing centered text and underlined etc... could be possible with a lot of textviews but is there a way not to use that much? Or maybe a way to type html and have the result?

How about use HTML tag?
myTextView.setText(Html.fromHtml("<u>Underlined</u>"));

Related

Set Text Customization in TextView

I have a text that is sometimes too high and at times one word.
How to put the text in this TextView so that the first two lines are located around the specified spacing?
Should this be done by 2 TextView?
If yes, how can I figure out how much text is placed on the top two lines?
You can use a Spannable to add customizations to a string inside a TextView.
The styling android blog has an excellent post about it: https://blog.stylingandroid.com/introduction-to-spans/
But looking to your print, it seems that the first row will always have a style and the rest another. With this, using two TextViews and customizing the view directly is a better option for code and performance.

Android - Appending text lines. Help choose the right control

Folks,
In my social networking application, single-line messages come from various users. As the message comes in, I need to display them in our UI as a single line that shows the time, the user, and the message line. All 3 fields need to be colored differently.
I tried to use TextView but am running into a problem. As I need various colors, I thought of using SpannableString but the problem is that TextView.Append does not support SpannableString as a parameter.
The other thought I had was to build html style text as each line comes in.
I am wondering if I am overlooking something. Perhaps there is a better user control or a better way to achieve my objective.
Thank you in advance for your help.
Regards,
Peter
Use Html and with help of <font color><font/> tag, you can set single text with different color#
String result="<font color=color_code>First Textview</font> <font color=color_code>Second Textview</font><font color=color_code>Third TextView</font>";
textview.setText(Html.fromHtml(result));
You should use three different text fields, nest them in a table layout using columns, or a relative layout. That way they will automatically resize no matter what length.
You can also use the android:weight tag to control how much room each one takes up.
The reason is that usually its 1 label per field in data structure. As per MVC software design pattern.

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

How to set text position in TextView via HTML?

I have a TextView in my application and a user can set any text in this TextView using HTML from the application settings. The user must be able to set the position of the parts of the text in this TextView using HTML tags. But TextView doesn't support 'table' tag or CSS. And I don't know how else to set the position. Is there some tag to set the position? Or maybe it is possible with HTML.TagHandler? If it is possible - how?
Two examples:
I want to set align="center" for one line in this TextView with HTML.
I want to separate text to two or three columns.
How can I do that?
I think what you are describing is a WYSIWYG editor like TinyMCE or CKEditor. These would allow you to align text or use tables to separate text into multiple columns.
to set align, line must have its id or class, without it maybe you can use jquery to find needed line ant align text in it.
Maybe text is splited into paragraphs, than you can find needed paragraph with jquery.
To split text to columns is not so easy, try this: How to divide text into columns, if I get text dynamically for database using Javascript and CSS?
You can try <div align="center">Your line here</div>.
Check out this article to see all the supported HTML tags

Android: How to display formated code in TextView?

I am writing an android application that will be displaying codes... specially java codes, or maybe jsp code as well. I was thinking about placing these codes in a TextView. However i dont know how to do this for android. I didnt find any tutorial or documentation on how to display formated text in a TextView. I know I can put html in there, so one direction would be format the code itself in html and then place it in the textview.
Is there a better way to do that?
Many thanks
T
TExtView can't do all the formatting. HTML is the best guess.
Search for "Spannable HTML Textview Android" and you will get quite a few examples. Here is one.
Is it possible to have multiple styles inside a TextView?

Categories

Resources