Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a TextView width in java

How can I set the TextView properties like width, height using Java Code?

like image 552
Annjo Avatar asked Oct 23 '10 14:10

Annjo


2 Answers

In the activity where you inflate the view, you can grab the TextView with

TextView t = (TextView)findViewById(R.id.myTextView);

where myTextView is the id that you declared in your XML.

Now go ahead and t.setText("Something");, t.setWidth(200), ...

like image 79
espinchi Avatar answered Oct 18 '22 08:10

espinchi


Here you have all TextView methods:

http://developer.android.com/reference/android/widget/TextView.html

If you read the complete page, then you will become a TextView guru.

like image 24
Cristian Avatar answered Oct 18 '22 08:10

Cristian