[英]How to take Password Text box in Xamarin using C# for Android
我需要使用c#移動應用程序為Xamarin應用程序輸入密碼文本框,因此我在main.xml中創建了兩個編輯文本,如下所示。
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<requestFocus />
</EditText>
<EditText
android:password="true"
android:id="@+id/txtPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textVisiblePassword" />
<requestFocus />
在我的“活動”中,我使用這樣的密碼:
var editPassword = new EditText(this);
editPassword.Id = Resource.Id.txtPassword;
但在“密碼文本”框中,文本顯示為正常而不是************。
您應該在條目中使用"IsPassword = true"
。
例如:
var password = new Entry { Placeholder = "Password", IsPassword = true };
@Racil Hilan提供的此解決方案對我有用
editText.InputType = Android.Text.InputTypes.TextVariationPassword | Android.Text.InputTypes.ClassText;
我在這里添加它是為了節省其他人的時間,因為在閱讀了該問題的答案(在某些情況下適用於我)后,帶我走了錯誤的道路,浪費了一個小時。
只是偶然發現了答案。
android:inputType =“ textPassword”可以與android:hint一起使用 ,
與android:password相同。 唯一的區別是,當我使用android:gravity =“ center”時 ,如果我使用的是android:inputType ,則不會顯示提示。 結案!
例:
<EditText
android:id="@+id/edittext_password_la"
android:layout_below="@+id/edittext_username_la"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dip"
android:inputType="textPassword"
android:hint="@string/string_password" />
采用
android:inputType="textPassword"
代替txtPassword
EditText的android:inputType="textVisiblePassword"
(這意味着應該是可見密碼的Text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.