How to set extra bold to text in string resources? - android

I have a question is there a way to set text the extra bold weight in a string resource?
this is what I have now:
<string name="home_text2>
<![CDATA[
some text<br/>
more text<br/>
<b>even more text</b>\u1433
]]>
</string>
The designer says all text should be in bold not just as i have it now in example string. which is easy setting android:textStyle="bold" in the text view. But how do I set part of the text in the example string as extra bold?
Been more specific I want to set the extra bold weight to the part of the text that now is just bold.
Thanks!

Nothing involving string resources or TextView support "extra bold" out of the box. You are welcome to try creating a custom CharacterStyle that implements "extra bold" by some means. Or, use a WebView. Or, draw text directly to a Canvas, with painting rules that implement "extra bold".

Related

How to add second text view just after completion of the first textview

I want to add second textview, just after completion of the first one. Linear layout with orientation horizontal didn't help.
Any other alternatives? Please suggest!
Generally, we use HTML text for this information.
We can use as many text styles as we want for different texts. With this way, you can set properties for each texts differently.
For Example: <HTML><text1><text2></HTML>
In the above, you can define text properties independently. Finally place this text in Textview. So we can achieve this using single TextView itself.
Example:
String str = "<a>This is a <font color='#800000FF'> blue text</font> and this is a <font color='red'> red text</font> </a>";
TextView textView = (TextView)findViewById(R.id.text);
textView.setText(Html.fromHtml(str, Html.FROM_HTML_MODE_COMPACT));

TextColors in a TextView

This may be a ridiculous question ever, but still I want to reduce my effort of creating a lot of text views.
I have text view that contains Name:Value format [Suppose Name:Android] In this case all the attributes for the text view will be same except the color and also the texts are side by side.
In real implementation I have to create two text views, and suppose if I have around 10-15 such pairs, the number of text views will be 20-30 respectively.
So how can I set different color for name and value independently??
Use something like
String str = "<font color=#900000 >Name:</font> <font color=#0000FF>Android</font>";
textview.setText(Html.fromHtml(str));
You can set the text to use html tags to set colors inside the text
String formattedText = "<font color=\"#ff0000\">red</font> <font color=\"#00ff00\">green</font>";
Spanned result = Html.fromHtml(formattedText);
view.setText(result);
Or, use spannable like in Set color of TextView span in Android

color string resource for xml layout

<string name="some_text">this is <font fgcolor="#ffff0000">red</font></string>
or
<string name="some_text">this is <font color="#ffff0000">red</font></string>
is not doing it.
I need to call the string in an xml TextView. How do I get it to work? No I don't want to use a horizontal LinearLayout with a bunch of TextViews.
You can't do this. instead of you can set TextView text as HTML like
textview.setText(Html.fromHtml("this is<font color=\"##ffff0000\">red</font>"));
Go to this for more HTML tag support information :html-tags-supported-by-textview
TextView doesn't support entering HTML text directly, though some of the other answers seem to show you how to get a Html object from the String. If you want to format the text within a TextView you need to use Spannable instances to format the sections of text to have different colours, fonts etc. This is only good if you don't already have your text in HTML though, of course.

How to span a textview in layout itself in android?

Can I span a textview to make some part bold in the layout itself. I have around 20 xml files. I am not using any activity for them, so I cannot do it programatically. So is there a way to specify it in xml layout itself. I have already tried using between them but it doesn't works.
android:text="Lets look how to make <b> negative sentences <b> in simple present tense."
doesn't work.
You can style a textView in xml but I believe it has to be a string resource rather than a hardcoded value like you are doing. Move the string to strings.xml and access it using resource id
android:text="#string/name"
Check this post.
Quoted from the post:
Supported HTML elements include:
<b> for bold text.
<i> for italic text.
<u> for underline text.
Check here
http://developer.android.com/reference/android/text/Spannable.html
or
https://sites.google.com/site/androidhowto/style-text
or
http://www.java2s.com/Code/Android/2D-Graphics/UsingSpannabletextandsetstyle.htm

Set text-size for part of the string

I had two strings:
<string name="bigtext">Big text</string>
<string name="anothertext">Small text</string>
I need them both in EditText's android:hint.
I tried to combine them & put "Big text" into <b>Big text</b>:
<string name="test">"<b>Big text</b> \nSmall text"</string>
"Big text" is bold, yep. But how to specify that "Big text" should have bigger font than "Small text"?
Add <big> tags around the big text. Or, if you prefer, add <small> tags around the small text. However, those will not work in a string resource AFAIK -- you would need to have this string in Java code or something, using Html.fromHtml() to get the SpannedString you would feed to setHint() on EditText.

Categories

Resources