1

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 click FontSize "26" then it should be able to change in that specific FontSize. Below I have an EditBox. So if I clicked Fontsize as 40 and in a Italic style than usual Bold. So I should be able to type inside EditBox with this selected "Font" : FontSize "40" and Italic style.

How could I do this programmatically in Android?

font=new Spinner(con);
option= new String[] {"Select Font Size","8","10","12","14","16","18","20",
                      "22","24","26","28","30","32","34","36","38","40","50"};
ArrayAdapter<String> adapter= new ArrayAdapter<String>(con,android.R.layout.simple_spinner_dropdown_item,option);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

font.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1,int position, long id) {
        option[1]="8";
       selectedItem= option[position];
    }
    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
    }
});
halfer
  • 19,824
  • 17
  • 99
  • 186
Achiever
  • 1,626
  • 10
  • 30
  • 54
  • 1
    Don't bother reading the [FAQ's](http://stackoverflow.com/faq) eh?? – Siddharth Lele Oct 03 '12 at 10:24
  • Actually, i wanna do it in globally. It shoud be applied for entire application. Not specifically to EditText alone . Even it should be able to apply it in my whole project. But really do not understand how to do entirely .. – Achiever Oct 03 '12 at 10:58

3 Answers3

5

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=".."
     ... />
Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
ColdFire
  • 6,764
  • 6
  • 35
  • 51
0

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.

Android
  • 3,828
  • 9
  • 46
  • 79
0

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);
}
Jake1164
  • 12,291
  • 6
  • 47
  • 64