TextView setWidth - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for TextView setWidth method.

This code example shows how to use the following methods:setOnCheckedChangeListener, setText, setWidth, setTextOff, setTextOn
		this.mLayout = new RelativeLayout(mContext);
		LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.FILL_PARENT);
		params.setMargins(0, 3, 0, 0);
		this.mLayout.setLayoutParams(params);
		this.mButton = new ToggleButton(mContext);
		this.mButton.setText("Torch");
		this.mButton.setTextOn("Torch");
		this.mButton.setTextOff("Torch");
		this.mButton.setWidth(LayoutParams.FILL_PARENT);
		this.mButton
				.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
 
					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						if (isChecked) {
							ledOn(); 
						} else { 
							ledOff(); 
						} 
6
CodeRank
This code example shows how to use the following methods:setPadding, setText, setWidth
        dialog.setTitle("Rate " + APP_TITLE);
 
        LinearLayout ll = new LinearLayout(mContext);
        ll.setOrientation(LinearLayout.VERTICAL);
         
        TextView tv = new TextView(mContext);
        tv.setText("If you enjoy using " + APP_TITLE + ", please take a moment to rate it. Thanks for your support!");
        tv.setWidth(240);
        tv.setPadding(4, 0, 4, 10);
        ll.addView(tv);
         
        Button b1 = new Button(mContext);
        b1.setText("Rate " + APP_TITLE);
        b1.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            	try { 
            		mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
            	} catch (ActivityNotFoundException e) {
            		mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + APP_PNAME)));
            	} 
7
CodeRank
This code example shows how to use the following methods:setBackgroundColor, setClickable, setLayoutParams, setHeight, setWidth
 
public class HorizontalEnvLine extends FrameLayout{
 
	public HorizontalEnvLine(Context context, int color,int length) {
		super(context);
		Button b= new Button(context);
		b.setClickable(false);
		b.setBackgroundColor(color);
		b.setHeight(2);
		b.setWidth(length);
		this.setBackgroundColor(Color.TRANSPARENT);
		FrameLayout.LayoutParams p= new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,1);
		p.gravity=Gravity.CENTER;
		b.setLayoutParams(p);
		this.addView(b);
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:setBackgroundColor, setClickable, setLayoutParams, setHeight, setWidth
 
public class HorizontalEnvLine extends FrameLayout{
 
	public HorizontalEnvLine(Context context, int color,int length) {
		super(context);
		Button b= new Button(context);
		b.setClickable(false);
		b.setBackgroundColor(color);
		b.setHeight(2);
		b.setWidth(length);
		this.setBackgroundColor(Color.TRANSPARENT);
		FrameLayout.LayoutParams p= new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,1);
		p.gravity=Gravity.CENTER;
		b.setLayoutParams(p);
		this.addView(b);
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:setClickable, setButtonDrawable, setPadding, setWidth
	@Override 
		// TODO Auto-generated method stub 
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout layout = new LinearLayout(mContext);
		layout.addView(new Button(mContext), new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
		CheckBox cb = new CheckBox(mContext);
		cb.setButtonDrawable(mResourceIds[position]);
		cb.setPadding(20, 0, 20, 0);
		cb.setWidth(128);
		cb.setClickable(false);
		layout.addView(cb);
		return layout;
	} 
} 
 
6
CodeRank

Related TextView setWidth Questions & Answers:

setWidth Method Overview
Makes the TextView exactly this many pixels wide.
See Code Examples for other Android TextView Methods: