android - Edittext Fonts Are Not Displaying -
android - Edittext Fonts Are Not Displaying -
i'm going through weird problem.
i have created customedittext class setting typeface whole application , works in cases.
i using circo.ttf
the problem when set android:inputtype="textpassword", text stops displaying after typing, maybe because font doesn't have password symbol or maybe there other problem.
below illustration of issue :
customedittext.java
public class customedittext extends edittext { public customedittext(context context) { super(context); changefonts(context); } public customedittext(context context, attributeset attrs) { super(context, attrs); changefonts(context); } public customedittext(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); changefonts(context); } @override protected void ondraw(canvas canvas) { // todo auto-generated method stub super.ondraw(canvas); } private void changefonts(context context) { // todo auto-generated method stub typeface tface = typeface.createfromasset(context.getassets(),"fonts/circo.ttf"); this.settypeface(tface); this.settextcolor(color.parsecolor("#921c50")); log.i("input type", "type : "+this.getinputtype()); } } login_main.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="20dp" android:orientation="vertical" android:gravity="center_vertical"> <com.equest.cwely.customviews.customtextview android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="login" android:textcolor="@color/border_pink" android:textstyle="bold" android:gravity="center" android:padding="10dp" android:layout_margintop="20dp" android:textappearance="?android:attr/textappearancelarge" /> <com.equest.cwely.customviews.customedittext android:id="@+id/edt_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="username" android:singleline="true" android:background="@drawable/edittext_bg" android:layout_margintop="10dp" android:ems="10" > <requestfocus /> </com.equest.cwely.customviews.customedittext> // password field <com.equest.cwely.customviews.customedittext android:id="@+id/edt_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:hint="password" android:background="@drawable/edittext_bg" android:singleline="true" android:layout_margintop="10dp" android:inputtype="textpassword" /> <linearlayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_margintop="10dp" android:padding="10dp" android:orientation="vertical"> <button android:id="@+id/btn_login" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:textcolor="@color/border_pink" android:layout_margin="5dp" android:background="@drawable/button_bg" android:text="login" /> <button android:id="@+id/btn_signup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:layout_margin="5dp" android:textcolor="@color/border_pink" android:background="@drawable/button_bg" android:text="sign up" /> </linearlayout> </linearlayout> loginactivity.java
public class loginactivity extends activity { button btn_login,btn_signup; edittext edt_username,edt_password; string result = ""; string username = "",password = ""; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.login_main); edt_username = (edittext)findviewbyid(r.id.edt_username); edt_password = (edittext)findviewbyid(r.id.edt_password); edt_password.settransformationmethod(new passwordtransformationmethod()); btn_login = (button)findviewbyid(r.id.btn_login); btn_login.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { username = edt_username.gettext().tostring(); password = edt_password.gettext().tostring(); //new dologin().execute(); } }); btn_signup = (button)findviewbyid(r.id.btn_signup); btn_signup.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { intent intent = new intent(getapplicationcontext(), registeractivity.class); startactivity(intent); } }); } }
it seems font have included not contain character symbol used default password transformation. have 2 options:
use different font
change mask character font contain.
because speculate you're not quitter, here's code alter mask character dot ( • ) asterisk ( * ).
first must create own passwordtransformationmethod override default:
public class asteriskpasswordtransformationmethod extends passwordtransformationmethod { @override public charsequence gettransformation(charsequence source, view view) { homecoming new passwordcharsequence(source); } private class passwordcharsequence implements charsequence { private charsequence msource; public passwordcharsequence(charsequence source) { msource = source; // store char sequence } public char charat(int index) { // create asterisk. if wish utilize // else alter returns homecoming '*'; } public int length() { homecoming msource.length(); // homecoming default } public charsequence subsequence(int start, int end) { homecoming msource.subsequence(start, end); // homecoming default } } }; finally set new transformation method edittext wish mask.
edt_password = (edittext)findviewbyid(r.id.edt_password); edt_password.settransformationmethod(new asteriskpasswordtransformationmethod()); i used info this question.
android android-edittext custom-controls android-typeface
Comments
Post a Comment