Skip to main content

Posts

Showing posts from August, 2017

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 = ...

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...

Android set the gravity for a TextView programmatically

Android set the gravity for a TextView programmatically  A1.        This will center the text in a text view: TextView ta = ( TextView ) findViewById ( R . layout . text_view ); LayoutParams lp = new LayoutParams (); lp . gravity = Gravity . CENTER_HORIZONTAL ; ta . setLayoutParams ( lp ); A2.      textView . setGravity ( Gravity . CENTER | Gravity . BOTTOM ); A3.              Use this code TextView textView = new TextView ( YourActivity . this ); textView . setGravity ( Gravity . CENTER | Gravity . TOP ); textView . setText ( "some text

Single TextView with multiple colored text ?

Single TextView with multiple colored text ? A1.              TextView TV = ( TextView ) findViewById ( R . id . mytextview01 ); Spannable word = new SpannableString ( "Your message" ); word . setSpan ( new ForegroundColorSpan ( Color . BLUE ), 0 , word . length (), Spannable . SPAN_EXCLUSIVE_EXCLUSIVE ); TV . setText ( word ); Spannable wordTwo = new SpannableString ( "Your new message" ); wordTwo . setSpan ( new ForegroundColorSpan ( Color . RED ), 0 , wordTwo . length (), Spannable . SPAN_EXCLUSIVE_EXCLUSIVE ); TV . append ( wordTwo ); A2.         You can use Spannable to apply effects to your TextView :         Here is my example for colouring just the first part of a TextView text (while allowing you to set         the color dynamically rather than hard coding it into a String as with the HT...

android TextView setting the background color dynamically doesn't work ?

android TextView setting the background color dynamically doesn't work ? A1.          To set red color: textView . setBackgroundColor ( 0xfff00000 );                                Or                                                                      <color name = "solid_red" > #fff00000 </color> textView.setBackgroundResource(R.color.solid_red); A2. if you are in activity use this textview . setBackground ( ContextCompat . getColor ( this , R . color . yourcolor ));           if you are in fragment use below code textview . setBackground ( ContextCompat . getColor ( getActivity (), R . color . yourcolor ));     ...

How to set the part of the text view is clickable?

How to set the part of the text view is clickable? A1. Cllickable span         Sample code: TextView myTextView = new TextView ( this ); String myString = "Some text [clickable]" ; int i1 = myString . indexOf ( "[" ); int i2 = myString . indexOf ( "]" ); myTextView . setMovementMethod ( LinkMovementMethod . getInstance ()); myTextView . setText ( myString , BufferType . SPANNABLE ); Spannable mySpannable = ( Spannable ) myTextView . getText (); ClickableSpan myClickableSpan = new ClickableSpan () { @Override public void onClick ( View widget ) { /* do something */ } }; mySpannable . setSpan ( myClickableSpan , i1 , i2 + 1 , Spannable . SPAN_EXCLUSIVE_EXCLUSIVE ); A2.        t = ( TextView ) findViewById ( R . id . PP1 ); t . setText ( Html . fromHtml ( "<bThis is normal text </b>" + "<a href=\"http...

How to set the text color of TextView in code?

 How to set the text color of TextView in code?  A1.          TextView text = ( TextView ) findViewById ( R . id . text ); text . setTextColor ( Color . parseColor ( "#FFFFFF" )); A2.       holder . text . setTextColor ( Color . rgb ( 200 , 0 , 0 ));       You can also specify what color you want with Transparency. holder . text . setTextColor ( Color . argb ( 0 , 200 , 0 , 0 ));       a for Alpha (Transparent) value r-red g-green b-blue A3.Adapter textview           Using Adapter you can set the text color by using this code: holder . text_view = ( TextView ) convertView . findViewById ( R . id . text_view ); holder . text_view . setTextColor ( Color . parseColor ( "#FF00FF" ));

TextView bold via xml file?

TextView bold via xml file?  A1.          following TextView : <TextView android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:textStyle = "bold" android:text = "@string/app_name" android:layout_gravity = "center" /> A2.         Just you need to use //for bold android : textStyle = "bold" //for italic android : textStyle = "italic" //for normal android : textStyle = "normal" < TextView android : layout_width = "match_parent" android : layout_height = "wrap_content" android : textStyle = "bold" android : text = "@string/userName" android : layout_gravity = "left" android : textSize = "16sp" /> A3.just           android : textStyle = "bold"

android ellipsize multiline textview ?

android ellipsize multiline textview ? A1. XML         android : maxLines = "2" android : ellipsize = "end" android : singleLine = "false" A2.        Try this, it works for me, I have 4 lines and it adds the "..." to the end of the last/fourth line.        Its  the same as morale's answer but i have singeLine="false" in there. <TextView android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:maxLines = "4" android:ellipsize = "marquee" android:singleLine = "false" android:text = "Hi make this a very long string that wraps at least 4 lines, seriously make it really A3.        There are a few attributes you should check: android:lines, android:minLines,                             android:maxLines. To display a maximum of 4 lines and ellipsiz...

How to change fontFamily of TextView in Android ?

How to change fontFamily of TextView in Android ? A1.Java-first copy .ttf in Assets folder           TextView tv = ( TextView ) findViewById ( R . id . appname ); Typeface face = Typeface . createFromAsset ( getAssets (), "fonts/epimodem.ttf" ); tv . setTypeface ( face );           A2:        Within the *.xml you can combine the stock fonts with the following functions, not only with              typeface: android : fontFamily = "serif" android : textStyle = "italic"       With this two styles, there was no need to use typeface in any other case. The range of                          combinations is much more bigger with fontfamily&textStyle A3.     You set style in res/layout/value/style.xml like that: <style name = "bold...

What is meant by Ems? (Android TextView)

What is meant by Ems? (Android TextView)  A1.         em is the typography unit of font width. one em in a 16-point typeface is 16 points A2.       It is the width of the letter M in a given english font size. So 2em is twice the width of the letter           M in this given font. In font differ from english it is the width of the widest letter in this font, this      width is different size in pixels then the width size of the M in the english font but it is still 1em .        So if I use text with 12sp in english font 1em is relative to this 12sp english font, using Italian font     with 12sp gives 1em that is differ in pixels width then the english one. A3.      TextView ems meaning    In TextView there is an attribute named android:ems. The description is "Makes the TextView be        exactly this many ems wide" ...