Android 密码提示字体与其他edittext字段不同
这是Android 密码提示字体与其他edittext字段不同,android,android-edittext,android-typeface,Android,Android Edittext,Android Typeface,这是TextInputLayout EditText password = (EditText) view.findViewById(R.id.etPassword); if (Build.VERSION.SDK_INT != android.os.Build.VERSION_CODES.KITKAT) { Typeface typeface = TypefaceUtil.overrideFont(getContext(), "SERIF", "fonts/calibr
TextInputLayout
EditText password = (EditText) view.findViewById(R.id.etPassword);
if (Build.VERSION.SDK_INT != android.os.Build.VERSION_CODES.KITKAT) {
Typeface typeface = TypefaceUtil.overrideFont(getContext(), "SERIF", "fonts/calibri.ttf");
password.setTypeface(typeface);
}
我正在尝试使用此代码,但我的密码提示字体样式与我设置的不同。我也面临此问题 你必须这样尝试,你会找到解决办法的 XML代码
<android.support.design.widget.TextInputLayout
android:id="@+id/inpPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/button_margin_small">
<android.support.design.widget.EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:hint="@string/set_pass"
android:inputType="textPassword"
android:maxLength="@integer/pass_max"
android:maxLines="1"
android:password="true"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
希望这能帮助您……我注意到,当输入类型为textPassword时,我的Edittext的字体样式不同。通过使用fontFamily属性修复了此问题 以下是我在布局中使用的代码:
EditText password = (EditText) findViewById(R.id.password_text);
password.setTypeface(Typeface.DEFAULT);
password.setTransformationMethod(new PasswordTransformationMethod());
除此之外,当iandroid:inputType=“textPassword”被删除并添加app:passwordToggleEnabled=“true”时,它会起作用
EditText密码=(EditText)view.findViewById(R.id.etPassword);
password.setTypeface(Typeface.DEFAULT);
setTransformationMethod(新的PasswordTransformationMethod());
使用android:fontfamine=“sans serif”
嘿,如果有人在使用kotlin,我希望这段代码能帮助你,它对我有用。我正在使用
com.google.android.material.textfield.TextInputLayout
和androidx.appcompat.widget.AppCompatEditText
在科特林:
<android.support.design.widget.TextInputLayout
android:id="@+id/inpPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/button_margin_small"
app:passwordToggleEnabled="true">
<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/set_pass"
android:maxLength="@integer/pass_max"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
EditText password = (EditText) view.findViewById(R.id.etPassword);
password.setTypeface(Typeface.DEFAULT);
password.setTransformationMethod(new PasswordTransformationMethod());
//查找视图
val etPassword=view.findviewbyd(R.id.etPassword)
//根据你的选择设置字体
etPassword.typeface=typeface.SANS_SERIF
//将其transformationMethod设置为PasswordTransformationMethod
etPassword.transformationMethod=PasswordTransformationMethod()
这是我的xml:
// find the view
val etPassword = view.findViewById<AppCompatEditText>(R.id.etPassword)
// set the typeface to your choice
etPassword.typeface = Typeface.SANS_SERIF
// the set its transformationMethod to PasswordTransformationMethod
etPassword.transformationMethod = PasswordTransformationMethod()
试试这个
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
在edittext xml中设置android:inputType=“text”
SetedtPassword.setTransformationMethod(新密码TransformationMethod())代码>在java文件中
适用于我的edittext自定义字体。您正在使用android:inputType=“textPassword”
以使其显示不同的字体。请删除此行android:inputType=“textPassword”
检查一次。请解释一下它有什么不同,并提供相关代码看看这个可能的副本是的,这很好,但不完全有效,只对删除android有效:inputType:“textPassword”
// find the view
val etPassword = view.findViewById<AppCompatEditText>(R.id.etPassword)
// set the typeface to your choice
etPassword.typeface = Typeface.SANS_SERIF
// the set its transformationMethod to PasswordTransformationMethod
etPassword.transformationMethod = PasswordTransformationMethod()
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<Edittext
android:id="@+id/edtPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="text"
android:textSize="14sp" />