Code example for TextView

Methods: setLayoutParamssetSingleLinesetTextsetTextColorsetTextSizesetTypeface

0
		LayoutParams textLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
		textLayoutParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
		textLayoutParams.setMargins(0, 0, 0, 0);
		textLayout.setLayoutParams(textLayoutParams);
 
		textView = new TextView(getContext());
		textView.setSingleLine(true);
		 
		LayoutParams textParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		textParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
		 
		if(this.text != null) {
			textView.setText(text);
		} 
	 
		if(textSize > 0) {
			textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
		} 
		else { 
			textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
		} 
		 
		textView.setTypeface(Typeface.DEFAULT_BOLD);
		textView.setTextColor((textColor == null) ? DEFAULT_TEXT_COLOR : textColor);
		textView.setLayoutParams(textParams);
		 
		textLayout.addView(textView);
		 
/****************************************** 
 * Flipper 
Contextual code suggestions in your IDE  Get Codota for Java