2014-02-13 9 views
0

사용자 정의 글꼴로 응용 프로그램을 개발 중입니다. 활자체가 잘 작동하도록 설정하고 있지만, 내 액티비티의 모든 editTexts에 TypeFace를 설정하는 것이 더 좋습니다. 하나씩. 나는 실제로 그것을 어떻게하고 있어요 이된다다양한 editText에 서체 설정

Typeface font = Typeface.createFromAsset(this.getAssets(),"fonts/NeoSans.otf"); 
Typeface fontBold = Typeface.createFromAsset(this.getAssets(),"fonts/NeoSans-Bold.otf"); 


    edt_txt_nombre = (EditText) findViewById(R.id.edt_nombres); 
    edt_txt_apellido = (EditText) findViewById(R.id.edt_apellidos); 
    edt_txt_usuario = (EditText) findViewById(R.id.edt_usuario); 
    edt_txt_contrasena = (EditText) findViewById(R.id.edt_contrasena); 
    edt_txt_email = (EditText) findViewById(R.id.edt_email); 
    edt_txt_telefono = (EditText) findViewById(R.id.edt_telefono); 
    edt_txt_fecha = (EditText) findViewById(R.id.edt_fec_nac); 

    registrar.setTypeface(fontBold); 
    txt_nombre.setTypeface(font); 
    txt_apellido.setTypeface(font);  
    txt_telefono.setTypeface(font); 
    txt_fecha.setTypeface(font); 
    edt_txt_nombre.setTypeface(font); 
    edt_txt_apellido.setTypeface(font); 
    edt_txt_usuario.setTypeface(font); 
    edt_txt_contrasena.setTypeface(font); 
    edt_txt_email.setTypeface(font); 
    edt_txt_telefono.setTypeface(font); 
    edt_txt_fecha.setTypeface(font); 

는 그것을 할 수있는 더 좋은 (짧은) 방법이 있나요?

답변

1

당신은 EditText를 서브 클래스와 생성자에서 서체를 설정할 수 있습니다 :

public class MyEditText extends EditText { 

    // replace '...' with proper arguments 
    public MyEditText(...) { 
     super(...) 
     // fetch your font 
     this.setTypeface(myFont); 
    } 
} 

는 하위 클래스에서 EditText(Context context, AttributeSet attrs)EditText(Context context, AttributeSet attrs, int style) 생성자를 잊지 마십시오 당신의 레이아웃이 팽창 할 수 없게됩니다. 당신의 layout.xml에서

그리고 대신 새 MyEditText 서브 클래스를 참조하십시오

<com.myapp.MyEditText 
    ... /> 
내가하려고했던
+0

, 당신의 업데이트가 완전히 나 저장, 감사를! 잘 작동 – Aiapaec

+0

실제로, 처음에는, 나는 단 하나의 생성자로 노력했지만 충돌하지 않지만 fonttype은 3 개의 생성자를 오버라이드 할 수 있도록 설정되지 않았으며 또한 시간도 없었습니다. 1이 앱이 사용하는 앱인 것처럼 1을 테스트합니다. – Aiapaec