Skip to main content

Posts

How to change the font on the TextView?

   How to change the font on the TextView? A1.                            First download the .ttf file of the font you need ( arial.ttf ). Place it in the                                      assets  folder(Inside assets folder create new folder named fonts and place it                                 inside it). If   txtyour is the textviews you want to apply the font , use the                                       following piece of code, Typeface type = Typeface . createFromAsset ( getAssets (), "fonts/Kokila.ttf" ); txtyour . setTypeface ( type ); A2.       Typeface tf = ...
Recent posts

Reset Android textview maxlines ?

Reset Android textview maxlines  ? A1.         Actually, the way android platform does that is by setting the MaxLine to                                            Integer.MAX_VALUE. textView . setMaxLines ( Integer . MAX_VALUE );        also, if you are using Ellipsize, don't forget to set to null. textView . setEllipsize ( null );       just check how the android framework do just that ;) watch the                                                              setMaxLines(Integer.MAX_VALUE); private void applySingleLine ( boolean singleLine , boolean applyTransformation ) { mSingleLine = singleLine ; if ( singleLine ) { ...

TextView bold via xml file?

TextView bold via xml file?  A1.         <TextView android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:textStyle = "bold" android:text = "@string/app_name" android:layout_gravity = "center" /> A2.      use: android:textStyle="bold" <TextView android:id = "@+id/txtVelocidade" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:layout_above = "@+id/txtlatitude" android:layout_centerHorizontal = "true" android:layout_marginBottom = "34dp" android:textStyle = "bold" android:text = "Aguardando GPS" android:textAppearance = "?android:attr/textAppearanceLarge" />

A: How to set text color to a text view programmatically ?

How to set text color to a text view programmatically  ? A1.             Use,.. Color . parseColor ( "#bdbdbd" );             like, mTextView . setTextColor ( Color . parseColor ( "#bdbdbd" )); A2.   textView . setTextColor ( getResources (). getColor ( R . color . some_color )); Please note that from API 23, getResources().getColor() is deprecated. Use instead: textView . setTextColor ( ContextCompat . getColor ( context , R . color . some_color )); where the required color is defined in an xml as: <resources> <color name = "some_color" > #bdbdbd </color> </resources> A3.       TextView tt ; int color = Integer . parseInt ( "bdbdbd" , 16 )+ 0xFF000000 ; tt . setTextColor ( color );         also tt . setBackgroundColor ( Integer . parseInt ( "d4d446" , 16 )+ 0xFF000000 );  ...

How to click or tap on a TextView text ?

How to click or tap on a TextView text ? A1.            You can set the click handler in xml with these attribute: android : onClick = "onClick" android : clickable = "true"       Don't forget the clickable attribute, without it, the click handler isn't called. main.xml ... < TextView android : id = "@+id/click" android : layout_width = "wrap_content" android : layout_height = "wrap_content" android : text = "Click Me" android : textSize = "55sp" android : onClick = "onClick" android : clickable = "true" /> ... MyActivity.java public class MyActivity extends Activity { public void onClick ( View v ) { ... } } A2. This may not be quite what you are looking for but this is...

Android and   in TextView ?

Android and &nbsp; in TextView ? A1.            The TextView should respect the non breaking space <string name = "test" > Hello&#160;world </string>                                     or new TextView ( "Hello\u00A0world" ); A2.      One unique situation I ran into was adding a non-breaking space to a string resource that took               String.format parameters. <resources> <string name = "answer_progress" formatted = "false" > Answered %d of %d </string> </resources>       I tried to simply copy and past the non-breaking space character into the string and it was                     replaced       with a regular old space after compilin...