Android 如何使用setTransformationMethod(null)显示密码,同时保留眼睛图标
目前,我的密码输入文本字段设计如下Android 如何使用setTransformationMethod(null)显示密码,同时保留眼睛图标,android,Android,目前,我的密码输入文本字段设计如下 <android.support.design.widget.TextInputLayout android:layout_marginLeft="@dimen/trading_activity_horizontal_margin" android:layout_marginRight="@dimen/trading_activity_horizontal_margin" app:hintTextAppearance="@sty
<android.support.design.widget.TextInputLayout
android:layout_marginLeft="@dimen/trading_activity_horizontal_margin"
android:layout_marginRight="@dimen/trading_activity_horizontal_margin"
app:hintTextAppearance="@style/TradingWizardTextInputLayout"
app:passwordToggleEnabled="true"
android:id="@+id/password_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/wizard_password"
android:id="@+id/password_edit_text"
android:inputType="textPassword"
android:imeOptions="actionNext|flagNoExtractUi" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/password_text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
android:layout_marginLeft="@dimen/dimen_18"
android:layout_marginRight="@dimen/dimen_18">
<EditText
android:textSize="16sp"
android:paddingTop="0dp"
android:id="@+id/password_edit_text"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_hide_password"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
密码是可见的。但是,它也会使眼睛图标消失
<android.support.design.widget.TextInputLayout
android:id="@+id/password_text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
android:layout_marginLeft="@dimen/dimen_18"
android:layout_marginRight="@dimen/dimen_18">
<EditText
android:textSize="16sp"
android:paddingTop="0dp"
android:id="@+id/password_edit_text"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_hide_password"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/password_text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
android:layout_marginLeft="@dimen/dimen_18"
android:layout_marginRight="@dimen/dimen_18">
<EditText
android:textSize="16sp"
android:paddingTop="0dp"
android:id="@+id/password_edit_text"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_hide_password"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
如何使用setTransformationMethod(null)
显示密码,同时保留眼睛图标?而不是使用
app:passwordToggleEnabled="true"
<android.support.design.widget.TextInputLayout
android:id="@+id/password_text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
android:layout_marginLeft="@dimen/dimen_18"
android:layout_marginRight="@dimen/dimen_18">
<EditText
android:textSize="16sp"
android:paddingTop="0dp"
android:id="@+id/password_edit_text"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_hide_password"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
您可以设置“drawableRight”和touchListener以获得相同的效果。
代码是这样的
<android.support.design.widget.TextInputLayout
android:id="@+id/password_text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
android:layout_marginLeft="@dimen/dimen_18"
android:layout_marginRight="@dimen/dimen_18">
<EditText
android:textSize="16sp"
android:paddingTop="0dp"
android:id="@+id/password_edit_text"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_hide_password"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
XML
<android.support.design.widget.TextInputLayout
android:id="@+id/password_text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
android:layout_marginLeft="@dimen/dimen_18"
android:layout_marginRight="@dimen/dimen_18">
<EditText
android:textSize="16sp"
android:paddingTop="0dp"
android:id="@+id/password_edit_text"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_hide_password"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
并在活动中设置侦听器
<android.support.design.widget.TextInputLayout
android:id="@+id/password_text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
android:layout_marginLeft="@dimen/dimen_18"
android:layout_marginRight="@dimen/dimen_18">
<EditText
android:textSize="16sp"
android:paddingTop="0dp"
android:id="@+id/password_edit_text"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_hide_password"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
passwordEditText.setOnTouchListener(new ShowHidePassword());
希望这有帮助。没有。这不会改变任何事情。眼睛图标上仍然有一个对角叉号,密码仍然不可见。
<android.support.design.widget.TextInputLayout
android:id="@+id/password_text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
android:layout_marginLeft="@dimen/dimen_18"
android:layout_marginRight="@dimen/dimen_18">
<EditText
android:textSize="16sp"
android:paddingTop="0dp"
android:id="@+id/password_edit_text"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_hide_password"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>