Setting the text appearance of an android TextView in Java code - android

How can I set the text appearance of an android TextView to large in Java code? There is a method setTextAppearance(), but I don’t know how to use it.

Just try that:
textView.setTextAppearance(this, android.R.style.TextAppearance_Large);

Try this:
textView.setTextAppearance(android.R.style.TextAppearance_Large);

Related

Partly editing the text of a TextView

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.

how to set background of TextView to #android:drawable/dialog_holo_light_frame

i want to set the below xml code programmatically. i know about textView.setBackgroundResource(R.drawable...) but i am not able to set textView background to #android:drawable/dialog_holo_light_frame. Please suggest me suitable method.
android:background="#android:drawable/dialog_holo_light_frame"
Try to use the pattern of the code below:
textView.setBackgroundResource(android.R.drawable.dialog_holo_light_frame);
If you want to use and of the standard android resources you have to use android.R. folder rather than just R. . R. is for your own project. So do it like below -
textView.setBackgroundResource(android.R.drawable.dialog_holo_light_frame);
You can do like below:
yourTextView.setBackgroundResource(android.R.drawable.dialog_holo_light_frame);

Highlight-style effect with multiline text in Android

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>"));

Apply ARGB color to a textview programmatically

I'm currently using something like: TextView.SetBackgroundColor(Color.WHITE); in my java code. I'd like to be able to add some transparancy to the textview through the java... This is easy to do in the XML via #AARRGGBB format, but I have not found a way to accomplish this programmatically.
TextView.SetBackgroundColor(Color.argb(a_int, r_int, g_int, b_int));
Or:
TextView.SetBackgroundColor(Color.parseColor("#AARRGGBB"));
You can use
TextView.SetBackgroundColor(Color.parseColor("#AARRGGBB"));

Android TextView link without underline?

I use a TextView with links by this:
TextView tv ...
tv.setText( Html.fromHtml(somehtml))
It is ok to control the link color by setting attribute android:textColorLink, but can I remove the underline of it?
OK now with html anchor tag, to avoid the underline now use the property STYLE="text-decoration:none"
< a STYLE="text-decoration:none" HREF=\"link.html\">it has no underline < /a >
this must work with a WebView but in a TextView I was using Android 1.5, 1.6 and thats not possible. =(
Just remove the html < u > tag, that indicates an underline text !
Spanned android.text.Html.fromHtml(String source, ImageGetter imageGetter, TagHandler tagHandler)
The important part is the TagHandler. You have to implement one and then you can hopefully modify it.
Another solution:
handle textview link click in my android app

Categories

Resources