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 .
Related
I read on Stack Overflow how to create a custom bold font and a regular one:
How to create custom font family with bold font
But I'm struggling to understand how to implement this in my strings. Ordinarily you simply use <b></b> to make text bold, but this doesn't seem to work with my custom fonts. All the text remains the same.
I know that you have tried adding the bolded font to a font family, but it hasn't worked. You can try one of the ways below. It will work even if you do import a TTF font.
One way you can do it is in strings.xml
You can create a new string and then add the b to bold it like this:
<string name="my_string"><b> My String</b></string>
You will need to create one for each string that you want to bold.
Then in your layout file, you can set the android:text to one of the strings from strings.xml and you can set the android:fontFamilyto the TTF font.
You can also bold it programmatically using the SpannableString in Java. Check this article to see how to bold programmatically.
Hope it helps!
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
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.
is it possible to format text in rows in Listview using html? I need to use font, b, i tags
I use this code to fill ListView
setListAdapter(new ArrayAdapter<String>(MyActivity.this,R.layout.resultlist,v));
where v is a vector array filled with strings
Thanks
No, but you can use the xml attributes to format the text in a TextView. For example, you can use the android:textStyle attribute to make the text bold, or italic. So if you want bold, you can do android:textStyle="bold" or if you want both bold and italic you can do android:textStyle="bold|italic". If you want different parts of your string formatted differently, checkout this SO Post.
Well, you can use:
Html.fromHtml("text with html");
But, I think it will slow down your ListView. Try to use android styling in your R.layout.resultlist xml layout. I'm sure you can find a way to avoid html formatting.
I have a textview which should render its content with HTML formatting. From code, this can be achieved like this,
textView.setText(Html.fromHtml(someText));
Is there a way to do this through the XML?
I ask because i do not want to set the text through the code, In my case, the text comes from a DB call and displayed through an adapter.
Yes there are a bunch of (simple) tags that are understood by TextView -- if the text is set in XML from a string resource.
So basically
<TextView text="#string/foo" .. />
It is also possible to give templates like "Hello <b>%s</b>", but here you still need to run some code to fill in the value for %s
Have a look at http://developer.android.com/guide/topics/resources/string-resource.html for formatting hints and short examples.