Different color for each specific character - android

I have problem on Android to do rainbow programmatic color on TextView.
Here specific condition of TextView:
String on TextView may contain character and number in unspecific order.
Example: AA11BB22, X2YY3ZZA1
For character (A-Z), I wish to display color BLUE.
For number (1-9), I wish to display color RED.
Example: AA11BB22 will display 'AA', 'BB' will display BLUE, and '11', '22' will display RED in TextView.
I know, there few solution to do solve using generate Image or HTML on canvas.
Is better or worse to do generate TextView for each chunk of part then color it?
Or maybe your guys has elegant solution for my situation.
Thanks.

You can make use of Spannable. This link will help you to understand how to use Spannable http://www.chrisumbel.com/article/android_textview_rich_text_spannablestring

You should have a look at Spannable string. http://developer.android.com/reference/android/text/SpannableString.html. The link provided by android.fryo is good and has a complete example.

Related

TextVIew does not display "ț" symbol

I have a simple TextView, where I put a string like that: "Curăță corect urechile copilașului tău!". But I see the string on display like this "Cură ă corect urechile copilașului tău!" - just space between chars, where must be a "ț" symbol.
I checked the string in TextView by TextView.getText(), and I get my original string.
This is a screenshot, also the same problem in first title:
Try to set text in TextView using HTML. I hope this will work and may help you out.
myTextView.setText(Html.fromHtml("your_string"));
There is still space for the letters, so perhaps it's an issue with the styling.
Change the style to default, do the letters show up?
Try adding a shadow to the textviews and see if the shadow exists (maybe the letters are somehow transparent, or the same color as the background?)
It is more related to a font issue, default Android font doesn't support some characters. You need to try from a different font.
You can try from the following (but I think its not free)
http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=FontDownloads

Change font of superscript text

I am writing an view where I need to display superscript data. I am following this to achieve this.
Along this is there any way to change font size(in number) of superscript text.
EDIT
Commanware suggested link work great, except one thing. I need superscript bit above of base text. I'm updating image for same, please refer. I'm using same code with mention in reference code.
Here either can go for separate text view could be second priority solution. Any suggestion !
try this one this is working code:
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("04:30<sup><small>pm</small></sup>"));
you cant pass text size in numbers, yo have to change the size to string :
<font size="3" color="red">This is some text!</font>
Use this Code :
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("your Text <sup style="font-size:5(yourfontsize);">subscript</sup>"));
Try this and Let me know :)

Android textview different style for bold text

I have a long string, with multiple bold words inside the string.
The styling of the non bold sentences are done inside the TextView XML part and this is looking fine.
But i want to make the bold words bigger and thicker.
Is this possible to change this with XML?
for example:
<string name="long_text">This should be a <b>long</b> text with different <b>styling</b></string>
The bold words are supposed to be 1.5 times bigger
Or should i do this in the Java code?
yes you have to do this in java because there is no way to as per your requirement,
you can use TextAppearanceSpan in java code with Spannable
if i am getting you right than try the following..
textview.setText(Html.fromHtml(getResources().getString(R.string.long_text)));
Mark as right if it works for you .

Android: how to set an icon to the input type password

I have an Edit text field and set his inputType to "textPassword".
The default view shows little dot icons. I would like to increase their size. I assume that there's no "largeTextPassword" option and you should set this up yourself.
I made a new large dot icon and would like to place it in instead of the regular one. Now I use the setText() method to insert the text into it. How do I combine between those values?
I'v tried to increase the textSize but the padding drove me crazy on different screen sizes.
I'v tried to use the setCompoundDrawablesWithIntrinsicBounds(R.drawable.dot, 0, 0, 0) method but still, I'm not sure this the right way.
If someone can shed some light on this would be great.
Don't use android:inputType="textPassword" because this will replace the characters with the default dot character.
Add a TextWatcher and, as the user types, store/append the new character in/to a String and replace that character in the EditText with an ImageSpan of your own.

Android: Set text color dynamically for string variable to be appended

I have TextView. Using java code I want to set color for string variable that I have to append to the text. Variable is generated at run time.
I explored Spannable but you have to give start and end which is not fixed.
Any other way to fix this. Please help.
Code:
String text; (Filled at runtime)
//but I want it to be different color
textview.append(text);
You can do something like this to set the text in your TextView:
tv1.setText(Html.fromHtml("<font color='red'>R</font><font color='green'>G</font><font color='blue'>B</font>"));
The issue with this is that when you have just one text object you can only have one colour for it. You will have to use more then one text object (each with different colours) and juxtapose them in you design.

Categories

Resources