2013-06-04 39 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。

相关问题