我现在正在开发 Xamarin.Forms PCL 应用程序,我正在添加一个设置页面并需要一个密码字段,但由于 EntryCells 不支持 isPassword,我决定添加一个自定义渲染器。
我编写了 iOS 版本,它工作正常,但 Android 版本没有加星。
我的渲染器是
[assembly: ExportRenderer(typeof(PasswordEntryCell), typeof(PasswordEntryCellAndroid))]
namespace SocialNetwork.Droid.Renderers
{
public class PasswordEntryCellAndroid : EntryCellRenderer
{
protected override Android.Views.View GetCellCore(Cell item, Android.Views.View convertView, ViewGroup parent, Context context)
{
var cell = base.GetCellCore(item, convertView, parent, context) as EntryCellView;
if (cell != null)
{
var textField = cell.EditText as TextView;
textField.InputType = global::Android.Text.InputTypes.TextVariationPassword;
}
return cell;
}
}
}
最佳答案
对于 Android.Widget.EditText
设置 InputType
和 TransformationMethod
var textField = FindViewById<EditText>(Resource.Id.textView1);
textField.InputType = global::Android.Text.InputTypes.TextVariationPassword;
textField.TransformationMethod = new Android.Text.Method.PasswordTransformationMethod();
注意:要显示密码,请将 TransformationMethod 指定为 null
;
注意:您应该将其转换为 EditText
var textField = cell.EditText as EditText; // TextView;
关于c# - Android 密码 EntryCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49397289/