Best code examples for Android TextView class (android.widget.TextView)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android TextView class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android TextView examples from Open Source projects
Examples using Android TextView getImeOptions method:
This code example shows how to use the following methods: getImeOptions, setImeOptions, setFocusable, setFocusableInTouchMode, setLayoutParams
67:	textView.setOnKeyListener(this); 
-
70:	textView.setLayoutParams(textBoxLayoutParams); 
71:	textView.setFocusable(true); 
72:	textView.setFocusableInTouchMode(true); 
73:	textView.setImeOptions(textView.getImeOptions() | EditorInfo.IME_FLAG_NO_EXTRACT_UI); 
Full Snippet Info
8
CodeRank
Examples using Android TextView setPadding method:
This code example shows how to use the following methods: setPadding, setText, setTextColor, setTextSize
174:	textView.setPadding((int)(20 * scale) * (leftPadding ? 2 : 1), (int)(20 * scale) * (!leftPadding && topPadding ? 1 : 0), (int)(20 * scale), 0); 
175:	textView.setText(item); 
176:	textView.setTextColor(Color.BLACK); 
177:	textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setGravity, setPadding, setText, setLayoutParams
116:	TextView textView = new TextView(ExpandableList1.this); 
117:	textView.setLayoutParams(lp); 
-
119:	textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); 
-
121:	textView.setPadding(36, 0, 0, 0); 
-
128:	textView.setText(getChild(groupPosition, childPosition).toString()); 
Full Snippet Info
8
CodeRank
Examples using Android TextView setText method:
This code example shows how to use the following methods: setText, getVisibility, setVisibility
116:	mTitleView.setText(title); 
-
118:	if (mTitleView.getVisibility() != VISIBLE) mTitleView.setVisibility(VISIBLE); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setText
80:	TextView txt=new TextView(this); 
-
90:	txt.setText(String.valueOf(runtime)+" seconds since activity launched"); 
-
93:	getListView().postDelayed(new Runnable() { 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setText, setTag, setVisibility
109:	view.setText(html); 
-
113:	view.setVisibility(VISIBLE); 
114:	view.setTag(null); 
-
119:	view.setText(null); 
120:	view.setVisibility(GONE); 
121:	view.setTag(null); 
-
180:	view.setTag(id); 
Full Snippet Info
8
CodeRank
Examples using Android TextView setGravity method:
This code example shows how to use the following methods: setGravity, setText, setLayoutParams
122:	TextView tv = new TextView(getActivity()); 
123:	tv.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, 
-
125:	tv.setText("Fragment #" + mNum); 
126:	tv.setGravity(CENTER); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setGravity, setPadding, setText, setId, setVisibility
95:	mStandardEmptyView = new TextView(context); 
96:	mStandardEmptyView.setId(INTERNAL_EMPTY_ID); 
97:	mStandardEmptyView.setGravity(Gravity.CENTER); 
98:	mStandardEmptyView.setVisibility(View.GONE); 
99:	mStandardEmptyView.setPadding(10, 15, 10, 15); 
100:	mStandardEmptyView.setText("That's all, folks!"); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setGravity, setPadding, setText, setTextSize
65:	TextView scoreText = new TextView(parent.getContext()); 
66:	scoreText.setText(String.valueOf(score.getScore())); 
67:	scoreText.setGravity(Gravity.RIGHT); 
68:	scoreText.setPadding(10, 10, 10, 10); 
69:	scoreText.setTextSize(16); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setCompoundDrawablesWithIntrinsicBounds, setGravity, setPadding, setText, setLayoutParams
142:	TextView textView = new TextView(ActivityPickerActivity.this); 
143:	textView.setLayoutParams(lpGroup); 
144:	textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); 
145:	textView.setPadding(leftPadding, 0, 0, 0); 
-
172:	textView.setText(info.applicationInfo.loadLabel(mPackageManager)); 
173:	textView.setCompoundDrawablesWithIntrinsicBounds(Utilities.createIconThumbnail(info.applicationInfo.loadIcon(mPackageManager),ActivityPickerActivity.this), null, null, null); 
Full Snippet Info
8
CodeRank
Examples using Android TextView setTextColor method:
This code example shows how to use the following methods: setText, setTextColor, setTextSize, setLayoutParams
69:	textView = new TextView(context); 
70:	textView.setTextSize(16); 
71:	textView.setTextColor(0xffffffff); 
72:	textView.setText(textId); 
73:	textView.setLayoutParams(new LinearLayout.LayoutParams( 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setText, setTextColor
308:	subText.setText(error.message()); 
-
311:	subText.setTextColor(Color.RED); 
-
315:	subText.setTextColor(Color.rgb(255,192,0)); 
-
318:	subText.setTextColor(Color.BLUE); 
-
321:	subText.setTextColor(Color.LTGRAY); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setTextColor, getBottom, getTop, layout
190:	view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom()); 
191:	view.setTextColor(Color.rgb( 
Full Snippet Info
8
CodeRank
Examples using Android TextView getText method:
This code example shows how to use the following methods: getText, setText, getWindowToken
74:	adapter.add(v.getText().toString()); 
75:	v.setText(""); 
-
80:	imm.hideSoftInputFromWindow(v.getWindowToken(), 0); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getText, getTextColors, getTextSize
64:	if (tv.getText().toString().startsWith(TEXT_SEARCH_PREFIX)) { 
65:	int textColour = tv.getTextColors().getDefaultColor(); 
66:	TextAppearance appearance = new TextAppearance(textColour, tv.getTextSize()/displayMetrics.scaledDensity); 
-
68:	if (TEXT_SEARCH_TEXT.equals(tv.getText().toString())) { 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getText, setText
29:	TextView textView = new TextView(context); 
30:	textView.setText(Html.fromHtml("<b>some</b> html text")); 
31:	assertThat(textView.getText().toString()).isEqualTo("<b>some</b> html text"); 
Full Snippet Info
8
CodeRank
Examples using Android TextView setEllipsize method:
This code example shows how to use the following methods: setEllipsize, setSingleLine, setText, setTextAppearance, setVisibility
239:	mTimeTextView = new TextView(mContext); 
240:	mTimeTextView.setSingleLine(true); 
241:	mTimeTextView.setEllipsize(TruncateAt.END); 
242:	mTimeTextView.setTextAppearance(mContext, android.R.style.TextAppearance_Small); 
-
245:	mTimeTextView.setText(text); 
246:	mTimeTextView.setVisibility(View.VISIBLE); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setEllipsize, setGravity, setSingleLine, setText, setTextAppearance
286:	mNameTextView = new TextView(mContext); 
287:	mNameTextView.setSingleLine(true); 
288:	mNameTextView.setEllipsize(TruncateAt.END); 
289:	mNameTextView.setTextAppearance(mContext, android.R.style.TextAppearance_Large); 
290:	mNameTextView.setGravity(Gravity.CENTER_VERTICAL); 
-
293:	mNameTextView.setText(text); 
294:	mNameTextView.setVisibility(View.VISIBLE); 
Full Snippet Info
8
CodeRank
Examples using Android TextView setMaxWidth method:
This code example shows how to use the following methods: setGravity, setMaxWidth, setMinWidth, setPadding, setText
66:	TextView messageText = new TextView(parent.getContext()); 
67:	messageText.setText(this.getMessageText(pos)); 
68:	messageText.setGravity(Gravity.LEFT); 
69:	messageText.setPadding(10, 10, 10, 10); 
70:	messageText.setMaxWidth(200); 
71:	messageText.setMinWidth(200); 
72:	messageText.setTextSize(16); 
Full Snippet Info
8
CodeRank
Examples using Android TextView setTextSize method:
This code example shows how to use the following methods: setGravity, setText, setTextColor, setTextSize, getHeight
94:	TextView textView = new TextView(context); 
95:	textView.setText(prompt); 
96:	textView.setTextSize(14); 
97:	textView.setTextColor(Color.BLACK); 
-
104:	LinearLayout.LayoutParams.WRAP_CONTENT,textView.getHeight()); 
-
108:	textView.setGravity(Gravity.CENTER); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setText, setTextSize, setTypeface, setLayoutParams
42:	tvFormattedName.setText("Add " + bookmark.getName()); 
43:	tvFormattedName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); 
44:	tvFormattedName.setTypeface(Typeface.DEFAULT_BOLD); 
-
48:	tvFormattedName.setLayoutParams(para); 
-
58:	tvFormattedName.setText("[" + bookmark.getObjectType() + "] " + bookmark.getName()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setGravity, setText, setTextSize
13:	TextView textView = new TextView(this); 
14:	textView.setText("Activity two"); 
15:	textView.setGravity(Gravity.CENTER); 
16:	textView.setTextSize(48); 
Full Snippet Info
8
CodeRank
Examples using Android TextView setLinkTextColor method:
This code example shows how to use the following methods: setLinkTextColor, setMovementMethod, setPadding, setText, setTextColor
46:	TextView tv = new TextView(this); 
47:	tv.setTextColor(0xffffffff); 
48:	tv.setLinkTextColor(0xffa3b8fe); 
-
50:	tv.setPadding(p, p, p, p); 
51:	tv.setText(Html.fromHtml(getIntent().getStringExtra("info"))); 
52:	tv.setMovementMethod(LinkMovementMethod.getInstance()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getText, setLinkTextColor, addLinks
45:	if(!TextUtils.isEmpty(notesPreview.getText())) { 
46:	notesPreview.setLinkTextColor(Color.rgb(100, 160, 255)); 
47:	Linkify.addLinks(notesPreview, Linkify.ALL); 
Full Snippet Info
8
CodeRank
Examples using Android TextView beginBatchEdit method:
This code example shows how to use the following methods: beginBatchEdit, endBatchEdit, onTextContextMenuItem
145:	mTextView.beginBatchEdit(); 
146:	mTextView.onTextContextMenuItem(id); 
147:	mTextView.endBatchEdit(); 
Full Snippet Info
8
CodeRank
Examples using Android TextView getLinksClickable method:
This code example shows how to use the following methods: getLinksClickable, getText, setMovementMethod, setText
34:	CharSequence content = view.getText(); 
35:	view.setText(convertNormalStringToSpannableString(content.toString())); 
36:	if (view.getLinksClickable()) { 
37:	view.setMovementMethod(LongClickableLinkMovementMethod.getInstance()); 
Full Snippet Info
8
CodeRank
Examples using Android TextView getTypeface method:
This code example shows how to use the following methods: getTypeface, setTypeface
66:	if(flags < 0 && textView.getTypeface() != null){ 
67:	flags = textView.getTypeface().getStyle(); 
-
78:	textView.setTypeface(currentFont, Typeface.MONOSPACE.BOLD); 
-
81:	textView.setTypeface(currentFont, Typeface.MONOSPACE.ITALIC); 
-
84:	textView.setTypeface(currentFont, Typeface.MONOSPACE.BOLD_ITALIC); 
-
88:	textView.setTypeface(currentFont, Typeface.MONOSPACE.NORMAL); 
-
92:	textView.setTypeface(currentFont, flags); 
Full Snippet Info
8
CodeRank
Examples using Android TextView getTextSize method:
This code example shows how to use the following methods: getTextSize, getTypeface
199:	paint.setTypeface(view.getTypeface()); 
200:	paint.setTextSize(view.getTextSize()); 
Full Snippet Info
7
CodeRank
Examples for other Android TextView methods:
Related Android TextView Questions & Answers:
Other Android TextView Examples
10:	        super.onCreate(savedInstanceState);
11:	        setContentView(R.layout.activity_main);
12:	        TextView view =  (TextView) findViewById(R.id.TextView02);
13:	        String s="";
14:	        for (int i=0; i < 500; i++) {
-
10:	        super.onCreate(savedInstanceState);
11:	        setContentView(R.layout.activity_main);
12:	        TextView view =  (TextView) findViewById(R.id.TextView02);
13:	        String s="";
14:	        for (int i=0; i < 500; i++) {

Read More

11:	
12:	public class ShowLocationActivity extends Activity implements LocationListener {
13:	  private TextView latituteField;
14:	  private TextView longitudeField;
15:	  private LocationManager locationManager;
-
12:	public class ShowLocationActivity extends Activity implements LocationListener {
13:	  private TextView latituteField;
14:	  private TextView longitudeField;
15:	  private LocationManager locationManager;
16:	  private String provider;
-
21:	    super.onCreate(savedInstanceState);
22:	    setContentView(R.layout.main);
23:	    latituteField = (TextView) findViewById(R.id.TextView02);
24:	    longitudeField = (TextView) findViewById(R.id.TextView04);
25:	
-
22:	    setContentView(R.layout.main);
23:	    latituteField = (TextView) findViewById(R.id.TextView02);
24:	    longitudeField = (TextView) findViewById(R.id.TextView04);
25:	
26:	    // Get the location manager

Read More

1:	
2:		TextView txtMessage;
3:	
4:		// Animation
-
10:			setContentView(R.layout.activity_fadein);
11:	
12:			txtMessage = (TextView) findViewById(R.id.txtMessage);
13:	
14:			// load the animation

Read More

11:	        this.setContentView(R.layout.single_list_item_view);
12:	        
13:	        TextView txtProduct = (TextView) findViewById(R.id.product_label);
14:	        
15:	        Intent i = getIntent();
-
11:	        this.setContentView(R.layout.single_list_item_view);
12:	        
13:	        TextView txtProduct = (TextView) findViewById(R.id.product_label);
14:	        
15:	        Intent i = getIntent();

Read More

0:	TextView txtView1, txtView2;
1:	Animation animFadeIn, animFadeOut;
2:	.

Read More

3:	
4:	    private MyFirstTestActivity mFirstTestActivity;
5:	    private TextView mFirstTestText;
6:	
7:	    public MyFirstTestActivityTest() {
-
14:	        mFirstTestActivity = getActivity();
15:	        mFirstTestText =
16:	                (TextView) mFirstTestActivity
17:	                .findViewById(R.id.my_first_test_text_view);
18:	    }

Read More

12:	                mClickFunActivity
13:	                .findViewById(R.id.launch_next_activity_button);
14:	        mInfoTextView = (TextView) 
15:	                mClickFunActivity.findViewById(R.id.info_text_view);
16:	    }

Read More

2:	editText.setOnEditorActionListener(new OnEditorActionListener() {
3:	    @Override
4:	    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
5:	        boolean handled = false;
6:	        if (actionId == EditorInfo.IME_ACTION_SEND) {

Read More

TextView Class Overview
Displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing; see EditText for a subclass that configures the text view for editing.

To allow users to copy some or all of the TextView's value and paste it somewhere else, set the XML attribute android:textIsSelectable to "true" or call setTextIsSelectable(true). The textIsSelectable flag allows users to make selection gestures in the TextView, which in turn triggers the system's built-in copy/paste controls....
Methods
  • addTextChangedListener
    Adds a TextWatcher to the list of those whose methods are called whenever this TextView's text changes.
  • append
    Convenience method: Append the specified text to the TextView's display buffer, upgrading it to BufferType.EDITABLE if it was not already editable.
  • extractText
    If this TextView contains editable content, extract a portion of it based on the information in request in to outText.
  • getError
    Returns the error message that was set to be displayed with setError(CharSequence), or null if no error was set or if it the error was cleared by the widget after user input.
  • getGravity
    Returns the horizontal and vertical alignment of this TextView.
  • getLinksClickable
    Returns whether the movement method will automatically be set to LinkMovementMethod if setAutoLinkMask(int) has been set to nonzero and links are detected in setText(char[], int, int).
  • getText
    Return the text the TextView is displaying.
  • getTextColors
    Gets the text colors for the different states (normal, selected, focused) of the TextView.
  • length
    Returns the length, in characters, of the text managed by this TextView
  • onCommitCompletion
    Called by the framework in response to a text completion from the current input method, provided by it calling InputConnection.commitCompletion().
  • onCommitCorrection
    Called by the framework in response to a text auto-correction (such as fixing a typo using a a dictionnary) from the current input method, provided by it calling commitCorrection(CorrectionInfo) InputConnection.commitCorrection()}.
  • onTouchEvent
    Implement this method to handle touch screen motion events.
  • removeTextChangedListener
    Removes the specified TextWatcher from the list of those whose methods are called whenever this TextView's text changes.
  • setCompoundDrawables
    Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.
  • setEllipsize
    Causes words in the text that are longer than the view is wide to be ellipsized instead of broken in the middle.
  • setError
    Sets the right-hand compound drawable of the TextView to the "error" icon and sets an error message that will be displayed in a popup when the TextView has focus.
  • setFilters
    Sets the list of input filters that will be used if the buffer is Editable.
  • setGravity
    Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself.
  • setHeight
    Makes the TextView exactly this many pixels tall.
  • setHint
    Sets the text to be displayed when the text of the TextView is empty.
  • setImeOptions
    Change the editor type integer associated with the text view, which will be reported to an IME with imeOptions when it has focus.
  • setInputType
    Set the type of the content with a constant as defined for inputType.
  • setLines
    Makes the TextView exactly this many lines tall.
  • setMaxHeight
    Makes the TextView at most this many pixels tall.
  • setMaxLines
    Makes the TextView at most this many lines tall.
  • setMaxWidth
    Makes the TextView at most this many pixels wide
  • setMinLines
    Makes the TextView at least this many lines tall.
  • setMinWidth
    Makes the TextView at least this many pixels wide
  • setMovementMethod
    Sets the movement method (arrow key handler) to be used for this TextView.
  • setPaintFlags
    Sets flags on the Paint being used to display the text and reflows the text if they are different from the old flags.
  • setRawInputType
    Directly change the content type integer of the text view, without modifying any other state.
  • setShadowLayer
    Gives the text a shadow of the specified radius and color, the specified distance from its normal position.
  • setSingleLine
    Sets the properties of this field (lines, horizontally scrolling, transformation method) to be for a single-line input.
  • setTextAppearance
    Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.
  • setTextSize
    Set the default text size to the given value, interpreted as "scaled pixel" units.
  • setTypeface
    Sets the typeface and style in which the text should be displayed, and turns on the fake bold and italic bits in the Paint if the Typeface that you provided does not have all the bits in the style that you specified.
  • setWidth
    Makes the TextView exactly this many pixels wide.