在我的布局中,我有经典的用户名/密码表单字段,并带有显示密码切换:
<EditText
style="@style/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:maxLines="1" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
<EditText
style="@style/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
和样式/ editText是
<style name="editText" parent="Widget.AppCompat.EditText">
<item name="android:paddingLeft">@dimen/dp10</item>
<item name="android:background">@color/white</item>
<item name="android:textSize">@dimen/sp16</item>
<item name="android:fontFamily">@font/rbt_bold</item>
<item name="android:textStyle">bold</item>
</style>
并且font / rbt_bold是
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:font="@font/roboto_bold"
android:fontStyle="normal" />
</font-family>
现在看来,密码edittext的样式不正确:
https://i.stack.imgur.com/LCKOB.png
怎么了?
答案 0 :(得分:1)
使用:
<com.google.android.material.textfield.TextInputLayout
app:endIconMode="password_toggle"
android:hint="Password"
app:endIconTint="@color/text_input_passwordtoggle_selector_color"
style="@style/CustomTIL"
..>
<com.google.android.material.textfield.TextInputEditText
android:inputType="textPassword"
.../>
</com.google.android.material.textfield.TextInputLayout>
具有自定义样式:
<style name="CustomTIL" parent="Widget.MaterialComponents.TextInputLayout.FilledBox" >
<item name="materialThemeOverlay">@style/CustomThemeOverlay_FilledBox</item>
</style>
<style name="CustomThemeOverlay_FilledBox">
<item name="editTextStyle">@style/CustomTextInputEditText_FilledBox</item>
</style>
<style name="CustomTextInputEditText_FilledBox" parent="Widget.MaterialComponents.TextInputEditText.FilledBox">
<item name="android:textAppearance">...yourTextAppearance...</item>
</style>