Dan
Dan

Reputation: 1110

Android password EntryCell

I am working on a Xamarin.Forms PCL app right now I am adding a Settings Page and a need a password field but since EntryCells don't support isPassword I decided to add a custom renderer.

I coded the iOS version and it works fine but the Android version doesn't star it.

My Renderer is

[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;
    }
}
}

Upvotes: 2

Views: 528

Answers (1)

SushiHangover
SushiHangover

Reputation: 74209

For an Android.Widget.EditText set the InputType and TransformationMethod

var textField = FindViewById<EditText>(Resource.Id.textView1);
textField.InputType = global::Android.Text.InputTypes.TextVariationPassword;
textField.TransformationMethod = new Android.Text.Method.PasswordTransformationMethod();

Note: To show the password, assign the TransformationMethod to null;

Note: You should be casting it as an EditText

var textField = cell.EditText as EditText; // TextView;

Upvotes: 2

Related Questions