Font Family change on View dynamically Android Example

TypeFace, setTypeface, font, font family, array of String, Button create dynamically

@Override
protected void onStart() {
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
  48,
  55
);	
Typeface typeFace = Typeface.MONOSPACE;	
String [] ar = {"A","B","C","D","E","F","G","H","J","K"};
for (int i = 0; i < ar.length; i++) {
Button buttonView = new Button(this);
buttonView.setText(Html.fromHtml("<b>"+ar[i]+"</b>"));
buttonView.setTextColor(Color.BLUE);
buttonView.setTextSize(27.f);
buttonView.setTypeface(typeFace,Typeface.BOLD);
buttonView.setOnClickListener(mThisButtonListener);
if(i%2==0)
	mLayoutButtons.addView(buttonView, p);
else
	mLayoutButtonsNextRow.addView(buttonView, p);
 
_listOfButtons.add(buttonView);
}
 
	super.onStart();
}
 
//////// xml file
<TextView
    android:id="@+id/text01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20dp"
    android:fontFamily="Arial"
 />
This entry was posted in Android Examples Code and tagged , , , . Bookmark the permalink.


Comments are closed.

5,299 views