Wednesday, February 18, 2015

How to create a text view programmatically with required attributes

Here I am providing a way to create a text view programmatically with required attributes. Please check and let me know if you have any query for me.

LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lparams .gravity = Gravity.CENTER;

TextView tv = new TextView(Myclass.this);
tv.setLayoutParams(lparams );
tv.setText(text + "");
tv.setTextSize(22);
tv.setPadding(5, 5, 5, 5);

// tv.setBackgroundColor(R.drawable.btn_gray_pressed);
tv.setGravity(Gravity.CENTER);
layout.addView(tvdate);//add to your main view

0 comments:

Post a Comment

Don't lose faith when you see others receive answers to their prayers

An elephant and a dog became pregnant at same time. Three months down the line the dog gave birth to six puppies. Six months later the dog...

 

G-Expo Template by Ipietoon Cute Blog Design