Java 想在我的android应用程序中显示密码切换/可见按钮吗
我有一个android应用程序的登录活动。由于测试,我经常输入我的密码,有时我不确定它是否是正确的密码,所以我需要完全删除它并再次输入。我认为这不是设计!我搜索了一下,发现有一个函数名为Java 想在我的android应用程序中显示密码切换/可见按钮吗,java,android,xml,Java,Android,Xml,我有一个android应用程序的登录活动。由于测试,我经常输入我的密码,有时我不确定它是否是正确的密码,所以我需要完全删除它并再次输入。我认为这不是设计!我搜索了一下,发现有一个函数名为app:passwordToggleEnabled=“true”。我试过了,但它出错了 我的代码: 您需要使用TextInputLayout,而不是EditText。EditText是一个功能较少的简单UI元素。TextInputLayout包括一个EditText和各种其他视图。使用此库,它可以很好地用于此目
app:passwordToggleEnabled=“true”
。我试过了,但它出错了
我的代码:
您需要使用TextInputLayout,而不是EditText。EditText是一个功能较少的简单UI元素。TextInputLayout包括一个EditText和各种其他视图。使用此库,它可以很好地用于此目的:
compile 'com.android.support:design:24.1.1'
例如:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/txtUsername"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/user"
android:drawableTint="#FF4081"
android:hint="User Name"
android:inputType="textEmailAddress"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
您需要TextInputLayout和TextInputItemText
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleContentDescription="description"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/colorAccent">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
您不能在文本和密码之间切换输入类型吗?ie
if(show)=选中,input type=text,else input type=password
(不用麻烦用正确的语法键入,抱歉)