How do you change text to bold in Android?

To do this in the layout.xml file: android:textStyle Examples: android:textStyle=”bold|italic” Programmatically the method is: setTypeface(Typeface tf) Sets the typeface and style in which the text should be displayed. Note that not all Typeface families actually have bold and italic variants, so you may need to use setTypeface(Typeface, int) to get the appearance that you actually … Read more

Android BroadcastReceiver onReceive Update TextView in MainActivity

In your MainActivity initialize a variable of MainActivity class like below. public class MainActivity extends Activity { private static MainActivity ins; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ins = this; } public static MainActivity getInstace(){ return ins; } public void updateTheTextView(final String t) { MainActivity.this.runOnUiThread(new Runnable() { public void run() { TextView textV1 = (TextView) … Read more

How to find android TextView number of characters per line?

Try this: private boolean isTooLarge (TextView text, String newText) { float textWidth = text.getPaint().measureText(newText); return (textWidth >= text.getMeasuredWidth ()); } Detecting how many characters fit will be impossible due to the variable width of the characters. The above function will test if a particular string will fit or not in the TextView. The content of … Read more

Android ImageGetter images overlapping text

You could change your cointainer c (view) to a textView and then make your onPostExecute look like this: @Override protected void onPostExecute(Drawable result) { // set the correct bound according to the result from HTTP call Log.d(“height”,””+result.getIntrinsicHeight()); Log.d(“width”,””+result.getIntrinsicWidth()); urlDrawable.setBounds(0, 0, 0+result.getIntrinsicWidth(), 0+result.getIntrinsicHeight()); // change the reference of the current drawable to the result // from … Read more

Apply two different font styles to a TextView

One way to do this is to extend TypefaceSpan: import android.graphics.Paint; import android.graphics.Typeface; import android.text.TextPaint; import android.text.style.TypefaceSpan; public class CustomTypefaceSpan extends TypefaceSpan { private final Typeface newType; public CustomTypefaceSpan(String family, Typeface type) { super(family); newType = type; } @Override public void updateDrawState(TextPaint ds) { applyCustomTypeFace(ds, newType); } @Override public void updateMeasureState(TextPaint paint) { applyCustomTypeFace(paint, newType); … Read more

Android active link of url in TextView

After revisiting all solutions, a summary with some explanations: android:autoLink=”web” will find an URL and create a link even if android:linksClickable is not set, links are by default clickable. You don’t have to keep the URL alone, even in the middle of a text it will be detected and clickable. <TextView android:text=”My web site: www.stackoverflow.com” … Read more