So, let's assume that I want to show a text such as : "Hello stranger ", using TextView. How would I do that? I realized that I cannot edit only a part of the text in TextView by changing textStyle attribute.
Use yourTextViewName.setText(Html.fromHtml(<b>Hello</b> <i>stranger</i>);
Reference here: https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String,%20int,%20android.text.Html.ImageGetter,%20android.text.Html.TagHandler)
Don't bother with complexity.
Place a TextView with the uneditable text on the left of the EditText. Change the margins and everything that makes it look like a unified view and you're done.
You can define the string in string.xml like this
<string name="text"><b>Hello</b><i>stranger</i></string>
and call it in your TextView like android:text="#string/text". It will work for you.
Related
What I would like to achieve is an effect that looks like this with a TextView:
Basically having a background, but keeping the space between the lines. The only solution I came up with was using one TextView for each line of text, but I would prefer a cleaner one using only one multiline TextView.
Any ideas?
Use spanned text for each line. Read the Spannable API.
please refer to this answer here as it describes how to implement spacing between multiple lines in a TextView , using the following properties :
android:lineSpacingMultiplier
android:lineSpacingExtra
Hope that Helps .
Regards
What you can do is use mark tag in html to textview.
myTextView.setText(Html.fromHtml("<mark>heading highlighted</mark>"));
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 .
In my application, I have an TextView with many lines beside of product, but I need the data with proper appearance.Is it possible to have justified alignment dynamically?
you can align your text dynamically some how as you want...
but, i guess there is no such facility available in android to fully justify text as the text editors does...
Use Html Formatting in your textView like
yourTextView.setText(Html.fromHtml("<h1>Product Name</h1><br><p>Content</p>"));
Yes you can get the instance of TextView on activity startup
TextView t = (TextView)FindViewById(R.id.TextView1)
t.setTextAppearance(context,parameter)
Suppose I have TextView and I want to change color of some part in it. Like this
And I must set OnclickListener on text " Terms Of Use ", so How can I do that but using two textViews. Thanks
Regards
Use a simple Checkbox with no text, and for text clicking event
this is what you are looking for Spannable
You can youse HTML in TextView:
myTextView.setText(Html.fromHtml("<h2>Test</h2>"));
I have a textview with fixed height. I want to set a long text, but text comes at the last line getting cut by half, I want to avoid it and want to show a continuation symbol. I am giving an image here, I wan to achieve it like in the image.
Use the ellipsize attribute of TextView. By setting :
<TextView
....
android:ellipsize="end">
</TextView>
if the text is longer than your TextView you will have dots(...) at the end of the TextView.
Two line of string only possible to do like this. set ellipsize = end in text view properties.
you should use \n and special symbols from google code.