要在EditText中設置啓用的密碼,我們必須在xml文件中設置「inputType」屬性。如果我們只使用EditText,那麼我們將在EditText中設置輸入類型,如下面的代碼所示。
<EditText
android:id="@+id/password_Edit"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:maxLength="100"
android:nextFocusDown="@+id/next"
android:layout_width="match_parent"
android:layout_height="match_parent" />
密碼啓用屬性是
android:inputType="textPassword"
但是,如果我們要實現與材料設計(設計支持庫)密碼的EditText那麼我們將不得不寫代碼給出波紋管。
<android.support.design.widget.TextInputLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/txtInput_currentPassword"
android:layout_width="match_parent"
app:passwordToggleEnabled="false"
android:layout_height="wrap_content">
<EditText
android:id="@+id/password_Edit"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="@string/hint_currentpassword"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:maxLength="100"
android:nextFocusDown="@+id/next"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.TextInputLayout>
@注意: - 在Android SDK 24及更高版本中,「passwordToggleEnabled」默認爲true。因此,如果我們在密碼EditText中有海關處理顯示/隱藏功能,那麼我們必須在代碼中將其設置爲false,如上所示。
app:passwordToggleEnabled="true"
要添加上面的行,我們必須在根佈局中添加下面的行。
xmlns:app="http://schemas.android.com/apk/res-auto"
您的會員命名風格會給您帶來麻煩。如果'Password'是一個真正存在的類,那麼上帝會提防靜態方法。 – 2011-05-23 09:02:44
我試過重命名..仍然沒有運氣 – Dhanesh 2011-05-23 09:25:14
我明白..非常感謝.. :) – Dhanesh 2011-05-23 09:35:31