2013-06-04 67 views
2

我正在創建兩個edittext。除輸入類型外,所有屬性都相同。一個是電子郵件,另一個是密碼。如果我刪除android:inputType寬度沒有變化。爲什麼edittext的寬度不同

   <EditText 
        android:id="@+id/edittext_email" 
        android:layout_width="wrap_content" 
        android:layout_height="40dp" 
        android:layout_marginTop="10dp" 
        android:background="@drawable/custom_edit" 
        android:ems="12" 
        android:hint="@string/email_address" 
        android:inputType="textEmailAddress" 
        android:paddingLeft="10dp" /> 

       <EditText 
        android:id="@+id/edittext_password" 
        android:layout_width="wrap_content" 
        android:layout_height="40dp" 
        android:layout_marginTop="10dp" 
        android:background="@drawable/custom_edit" 
        android:ems="12" 
        android:hint="@string/password" 
        android:inputType="textPassword" 
        android:paddingLeft="10dp" /> 

enter image description here

+0

嘗試爲兩個編輯設置'android:textSize'爲相同的值,但不確定是否會幫助 – httpdispatch

+2

@ user527759:將無法使用,因爲字體不同 – njzk2

回答

6

正如你所說,這個問題是通過設置的inputType到textPassword在XML引起的(請注意,它也改變了文本的字體)。

嘗試這種解決方案:

1-保持的inputType密碼

2-添加以下代碼中包含EDITTEXT的觀點:

EditText password = (EditText) findViewById(R.id.edittext_password); 
password.setTypeface(Typeface.DEFAULT); 
password.setTransformationMethod(new PasswordTransformationMethod()); 

這實際上固定的字體,並希望編輯文本的大小。

1

不僅寬度,而且文本面也是不同的兩個盒子。它由於輸入類型的密碼。 您可以在代碼中設置文本字體爲password.setTypeface(Typeface.DEFAULT); 或不使用wrap_content。

相關問題