How To Apply FontSize Dynamically And Programmatically Without Using XML In Android?
Possible Duplicate: How to change the Font Size in a whole Application programmatically, Android? This is my Code : I have created Spinner with a list of FontSize options. If I
Solution 1:
to change
textSize use editText.setTextSize(20)
font and style use editText.setTypeface(yourTypeFace, Typeface.BOLD)
UPDATE
public class MyEditText extends EditText{
public MyEditText(Context context) {
super(context);
init();
}
public MyEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public MyEditText(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
void init() {
this.setTextSize(20);
this.setTypeface(yourTypeFace, Typeface.BOLD);
}
// method to change font settings
void setFont(TypeFace tf){
this.setTypeFace(tf);
}
//add whatever method you want
}
and then instead of using EditText
you use this class, and don't forget in your XML to use
<yourpackage.MyEditText
android:layout_height=".."
android:layout_width=".."
... />
Solution 2:
The probable solution would be you create a base class which extends TextView, and use this text view class as edit text. Hope you are asking for size in first screen. In any case, u set the text size in the base class. This will solve your problem.
like u create this class in package com.example and class name is BaseTextView, then in xml file instead of you will write
Hope this helps.
Solution 3:
First of all get the id of the EditBox. Then selected item's position. according to that you can make a formula like this:
public void onItemSelected(AdapterView<?> arg0, View arg1,int position, long id) {
int p=(8+(pos*2));
editText.setTextSize(p);
}
Post a Comment for "How To Apply FontSize Dynamically And Programmatically Without Using XML In Android?"