c# - Android 密码 EntryCell

标签 c# xamarin xamarin.forms xamarin.android

我现在正在开发 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 设置 InputTypeTransformationMethod

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/

相关文章:

android - Xamarin 工具->Android 菜单在 Visual Studio 2015 中被禁用

c# - 如何在 C# Visual Studio 调试器中显示 1000 分隔符

c# - 是否可以使用反射从通用实体访问属性(按名称)?

c# - Xamarin:运行进程时阻止 sleep 模式

Xamarin:使用具有 UICompletion 处理程序的 Notify 方法不可用

c# - FormsViewGroup.dll (v7.1) 的 $(TargetFrameworkVersion) 大于项目 (v6.0) 的 $(TargetFrameworkVersion) xamarin

c# - 打开 mysql 连接时出现 System.TypeInitializationException 错误

c# - 如何使用Angular个人用户帐户身份验证自定义ASP.NET Core Web应用程序的登录页面?

ListView 分隔符插入全宽

xaml - Visual Studio 2017 Xamarin Form 预览失败并出现 System.Exception - 无法呈现 Android XAML 预览