如何为android中的单个EditText设置两种字体?

时间:2016-02-15 07:19:09

标签: java android android-edittext android-typeface

这是ChooseLanguage类:

  languagelist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                   Toast.makeText(getApplicationContext(), "you select "+lag[position]+" language", Toast.LENGTH_LONG).show();
                     switch (position){
                         case 0:
                             mytranslate.TamilLanguage();
                             list_dialog.hide();
                             break;
                         case 1:
                             mytranslate.EnglishLanguage();
                             list_dialog.hide();
                             break;
                     }
                    }
                });
                list_dialog.show();
            }

这是Translate类:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample);

    e1=(EditText)findViewById(R.id.input1);
}
public void TamilLanguage(){
    final Typeface tamil_font = Typeface.createFromAsset(getApplication().getAssets(), "Tamil.ttf");
    e1.setTypeface(tamil_font);
    Toast.makeText(getApplicationContext(), "you select Tamil Language", Toast.LENGTH_LONG).show();

}
public void EnglishLanguage(){
    final Typeface english_font= Typeface.createFromAsset(getApplication().getAssets(), "English.ttf");
    e1.setTypeface(english_font);
    Toast.makeText(getApplicationContext(),"you select English Language",Toast.LENGTH_LONG).show();
}

我在ChooseLanguage课程中选择了字体,但在MyTranslate课程中它不起作用,这是我的代码,请参考。

如果我点击一个按钮,它将显示一个列表1.English 2.Tamil。如果我选择一种语言,它将改变edittext字体。

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

您需要刷新当前的活动。

Intent intent = getIntent();
    finish();
    startActivity(intent);